你可以發布任何包含**package.json**文件的目錄,比如Nodejs模塊。
## 創建用戶
發布包之前,你必須創建一個npm用戶賬號。如果還沒有,你可以用**npm adduser**創建一個。如果已經注冊了,使用**npm login**命令將賬號信息存儲到本地客戶端。
測試:使用**npm config ls**確認賬號信息已經存儲到您的客戶端。訪問https://npmjs.com/~ 以確保信息正確。
## 發布包
使用**npm publish**來發布程序包。
> Note that everything in the directory will be included unless it is ignored by a local **.gitignore** or **.npmignore** file as described in **npm-developers**.
注意,目錄下的所有文件都將被包含進去,除非目錄下有**.gitignore** 或 **.npmignore**文件(詳情請看**npm-developers**)將其排除。
> Also make sure there isn't already a package with the same name, owned by somebody else.
同時,請確保npm上沒有別的開發者提交的同名都包存在。
> Test: Go to **https://npmjs.com/package/<package>**. You should see the information for your new package.
測試:前往**https://npmjs.com/package/<package>**。你應該可以看到發布的新包的信息了。
## 更新包
> When you make changes, you can update the package using npm version <update_type>, where update_type is one of the semantic versioning release types, patch, minor, or major. This command will change the version number in package.json. Note that this will also add a tag with this release number to your git repository if you have one.
當你修改了你的包文件,你可以用`npm version <update_type>`更新它。update_type是指語義化版本管理的發布類型的一種:補丁版本(patch)、次版本(minor)或主版本(major)。此命令會更改package.json中的版本號。注意哦,如果你有此包的git倉庫,那么此命令也會向git倉庫添加此版本的一個標簽。
> After updating the version number, you can npm publish again.
更新版本號之后,你就可以再次 `npm publish` 了。
> Test: Go to https://npmjs.com/package/<package>. The package number should be updated.
測試:前往 **https://npmjs.com/package/<package>**,包的版本號應該已更新了。
> The README displayed on the site will not be updated unless a new version of your package is published, so you would need to run npm version patch and npm publish to have a documentation fix displayed on the site.
站點下的README文件是不會更新,除非你的包的新版本發布成功。所以你需要運行`npm version patch`和`npm publish`命令來修復站點下的文檔。