npm 常用操作

常用命令

  • npm -v #显示版本,检查npm是否正确安装。
  • npm install 模块名 #安装xxx的模块
  • npm install -g 模块名 #全局安装express模块
  • npm ls --depth 0 #列出已安装的模块
  • npm ls 模块名 #本地模块显示
  • npm show 模块名 #显示xxx模块详情
  • npm update #升级当前目录下项目所有模块
  • npm update 模块名 #升级当前目录下指定模块
  • npm update -g 模块名 #升级全局的xxx模块
  • npm uninstall 模块名 #删除指定模块
  • sudo npm update npm -g #npm升级自身
  • npm home 模块名 打开模块的主页
  • npm repo 模块名 打开模块的github地址
  • npm outdated 查看安装的模块是否过期,当前安装的版本(Current)、你应该要更新到的版本(Wanted)以及仓库中最新的版本(Latest)
  • npm install --production 之安装dependencies

切换数据源

nrm 是一个 NPM 源管理器,允许你快速地在如下 NPM 源间切换

安装

npm install -g nrm

列出可选的源

nrm ls
* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - http://registry.npm.taobao.org/
  eu ----- http://registry.npmjs.eu/
  au ----- http://registry.npmjs.org.au/
  sl ----- http://npm.strongloop.com/
  nj ----- https://registry.nodejitsu.com/

带 * 的是当前使用的源,上面的输出表明当前源是官方源。

切换

nrm use taobao

    Registry has been set to: http://registry.npm.taobao.org/

增加源

nrm add  <registry> <url> [home]

删除源

nrm del <registry> [your registry]

测试速度

测试单个

nrm test npm

    npm ---- 1328ms

测试所有

nrm test

调试本地包

# 进入基础库项目链接到全局
$ cd ~/workspace/scnode/blue-windy-sentry
$ npm link

up to date in 5.704s
/usr/local/lib/node_modules/@souche/blue-windy-sentry -> /Users/everlose/workspace/scnode/blue-windy-sentry

# 进入到业务项目
$ cd ~/workspace/scnode/msgcenter-sms
$ npm link @souche/blue-windy-sentry

/Users/everlose/workspace/scnode/msgcenter-sms/node_modules/@souche/blue-windy-sentry -> /usr/local/lib/node_modules/@souche/blue-windy-sentry -> /Users/everlose/workspace/scnode/blue-windy-sentry

# 取消链接
$ cd ~/workspace/scnode/msgcenter-sms
$ npm unlink @souche/blue-windy-sentry
原文地址:https://www.cnblogs.com/everlose/p/12840192.html