[javascript] node.js包管理工具 npm
npm 是node.js提供的包管理工具
# 安装指定名字的包 会下载到当前目录下 node_modules/<projectname> npm install <packagename> npm install <packagename>@<version> # 按版本号安装 npm install <packagename>@<tagname> # 按发布tag npm install <packagename>@">=<version>" # 按版本范围 npm install git://<gitdomain> # 按git路径 # 将安装包保存到全局目录(/usr/local/lib/node_modules)下 npm install <packagename> -g # 生成package.json文件 由按提示的输入的数据生成 npm init pakcage.json { "name" : "test_package", "version" : "0.0.1", "description" : "test", "main" : "index.js", "scripts" : { "test" : "node test.js" }, "repository" : "", "author" : "", "license" : "BSD", "dependencies" : { "express" : ">= 2.5.6", "mustache" : "0.4.0", "commander": "*" } } # 会按目录package.json文件中 dependencies在本地下载相关包 npm install # 更新指定的包 npm <packagename> # 查看所有的已安装的包 npm list ├── commander@1.0.1 ├─┬ express@3.0.0rc3 │ ├── commander@0.6.1 │ ├─┬ connect@2.4.3 │ │ ├── bytes@0.1.0 │ │ ├── formidable@1.0.11 │ │ ├── pause@0.0.1 │ │ └── qs@0.4.2 │ ├── cookie@0.0.4 │ ├── crc@0.2.0 │ ├── debug@0.7.0 │ ├── fresh@0.1.0 │ ├── methods@0.0.1 │ ├── mkdirp@0.3.3 │ ├── range-parser@0.0.4 │ └─┬ send@0.0.3 │ └── mime@1.2.6 └── mustache@0.4.0 # 查看当前包是否有新版本 npm outdated # 移除不再依赖的包 npm prune # link包目录(别的目录下link过来,win下木有用) npm link <path>/<packagename> # 和编译本地c++文件有关 npm rebuild # 运行脚本(package.json scripts中定义) npm run-script test # 打包生成<packagename>-<version>.tgz 文件 npm pack # 查找包 npmjs.com中 npm search <search term> # 到指定包的主页上去 npm home <packagename> # 和npmjs.com有关的命令 # 注册一个用户 npm adduser # 将包发布到npmjs上 npm publish npm unpublish <package>[@<version>] npm deprecate <packagename>[@<version>] <message> npm tag <name>@<version> [tag]
from: http://tobyho.com/2012/02/09/tour-of-npm/
think in coding