nvm、nrm、npm、yarn 小结

nvm (Node Version Manage)

  • https://github.com/coreybutler/nvm-windows
  • 常用命令:
    • nvm version
    • nvm install latest
    • nvm install 版本号
    • nvm uninstall 版本号
    • nvm list
    • nvm use 版本号

nrm

  • nrm 是一个管理 npm 源的工具。用来切换官方 npm 源和国内的 npm 源(如: cnpm),当然也可以用来切换官方 npm 源和公司私有 npm 源

  • 全局安装 npm i nrm -g

  • 查看当前 nrm 内置的几个 npm 源的地址: nrm ls

  • 切换到 cnpm:nrm use cnpm

npm

  • npm i express --save / npm i express -S (安装 express,同时将 express 写入依赖)

  • npm i express --save-dev / npm i express -D(安装express,同时将 express 写入devDependencies)

  • npm i express --save --save-exact(安装express,同时将 express 写入依赖 锁定版本

建议线上的Node.js应用都采取这种锁定版本号的方式

npm config set save-exact true

每次这样 npm i xxx --save 的时候会锁定依赖的版本号,加相当于了 --save-exact 参数。

小提示:npm config set 命令将配置写到了〜/ .npmrc文件,运行 npm config list 查看。

  • 其他常用的一些命令
npm config get registry  // 查看npm当前镜像源

npm config set registry https://registry.npm.taobao.org/  // 设置npm镜像源为淘宝镜像

yarn config get registry  // 查看yarn当前镜像源

yarn config set registry https://registry.npm.taobao.org/  // 设置yarn镜像源为淘宝镜像
- npm yarn
初始化 会自动生成一个package.json文件 npm init yarn init
添加模块 npm install 包名 yarn add 包名
删除模块 npm uninstall 包名 yarn remove 包名
更新模块 npm update 包名
查看node.js全局包的安装路径 npm root -g
查看当前项目npm包的安装路径 npm root
查看全局安装的包列表 npm list -g --depth 0 depth 0 是限制目录层级
清空缓存 npm cache clean
查看安装的模块及依赖 npm ls / list
cli commands https://docs.npmjs.com/cli-documentation/ https://yarnpkg.com/zh-Hans/docs/cli/

Mac npm 全局安装目录 /usr/local/lib/node_modules

npm nvm 一直提示 没权限

// liuxinya是用户名
sudo chown -R liuxinya ~/.npm
sudo chown -R liuxinya ~/.nvm

你可能感兴趣的:(nvm、nrm、npm、yarn 小结)