NPM是隨同NodeJS一起安裝的包管理工具,允許用戶從NPM服務器上傳下載安裝第三方包或命令行程序,能解決NodeJS代碼部署上的很多問題,非常方便。下面我們一起來看看常用的npm命令有哪些
使用方法:npm <command命令>,比如 npm -v表示查看版本號,以下是常用的命令 access, adduser, bin, bugs, c, cache, completion, config, ddp, dedupe, deprecate, dist-tag, docs, doctor, edit, explore, get, help, help-search, i, init, install, install-test, it, link, list, ln, login, logout, ls, outdated, owner, pack, ping, prefix, profile, prune, publish, rb, rebuild, repo, restart, root, run, run-script, s, se, search, set, shrinkwrap, star, stars, start, stop, t, team, test, token, tst, un, uninstall, unpublish, unstar, up, update, v, version, view, whoami
npm install :表示用npm 安裝 Node.js 模塊,比如用 npm 命令安裝常用的 Node.js web框架模塊 express:
npm install express
npm update:升級更新模塊
npm update express
npm uninstall:卸載模塊
npm uninstall express
npm search:搜索模塊
npm search express
npm 淘寶鏡像:大家都知道國內直接使用 npm 的官方鏡像是非常慢的,這里推薦使用淘寶 NPM 鏡像。淘寶 NPM 鏡像是一個完整 npmjs.org 鏡像,你可以用此代替官方版本(只讀),同步頻率目前為 10分鍾 一次以保證盡量與官方服務同步。你可以使用淘寶定制的 cnpm (gzip 壓縮支持) 命令行工具代替默認的 npm:
npm install -g cnpm --registry=https://registry.npm.taobao.org
這樣設置以后就可以使用 cnpm 命令來安裝模塊了:
cnpm install express