深入浅出Node.js (附录D)

D.1  NPM仓库的安装
  D.1.1  安装Erlang和CouchDB
  D.1.2  搭建NPM仓库
D.2  高阶应用
  D.2.1  镜像仓库
  D.2.2  私有模块应用
  D.2.3  纯私有仓库
D.3  总结
D.4  参考资源

1. what is npm
-- To upgrade: run: [sudo] npm install npm@latest -g

2. Installing Node.js and updating npm
-- node -v to test. The version should be higher than v0.10.32
-- sudo npm install npm -g
-- npm -v to test. The version should be higher than 2.1.8

3. Fixing npm permissions
-- find the path to npm's directory: npm config get prefix
-- change owner: sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} 

4. Installing npm packages locally
-- npm install <package_name>
-- ls node_modules

5. Using a package.json
-- To create package.json, run: npm init --yes
-- npm set init.author.email "wombat@npm.com" 

6. Updating local packages
-- npm update in the same directory as your package.json file
-- npm outdated to test

7. Uninstalling local packages
-- npm uninstall <package>
-- npm uninstall --save <package>

8. Installing npm packages locally
-- npm install -g <package_name>
-- sudo npm install -g <package>

9. Updating local packages
-- npm install -g <package>
-- npm outdated -g --depth=0 to find out which packages need to be updated
-- npm update -g to update all global packages

10. Uninstalling local packages
-- npm uninstall -g <package>

11. Creating Node.js module
author: Your Name <email@example.com> (http://example.com)
--Publish your package to npm
--Make a new directory outside of your project and cd into it
--Run npm install <package>
--Create a test.js file which requires the package and calls the method
--Run node test.js. The message should be output.

12. Publishing npm packages
--npm adduser/npm login to store the credentials on the client
--npm config ls
--npm publish. to check: https://npmjs.com/package/<package>
--npm version patch and npm publish to update package

13. Semantic versioning and npm

14. Working with scoped packages
-- @scope/project-name package's name begin with @, then it is a scoped package.
-- @username/project-name

--sudo npm install -g npm
--npm login

--npm init --scope=username package.json: {"name": "@username/project-name"}
--.npmrc npm config set scope username
--npm publish --access=public

--npm install @username/project-name --save
var projectName = require('@username/project-name')

15. Using dist-tags
--Tags are a supplement to semver for organizing and labeling different versions of packages.
--npm dist-tag add <pkg>@<version> [<tag>]
--npm publish --tag beta
--npm install somepkg@beta

原文地址:https://www.cnblogs.com/thlzhf/p/5155936.html