npm常用命令
npm常用命令
npm安装配置相关:
# 查看 npm 的版本
$ npm -v //6.4.0 << 安装成功会返回版本号
# 查看各个命令的简单用法
$ npm -l
# 查看 npm 命令列表
$ npm help
# 查看 npm 安装目录
$ npm root -g
# 查看 npm 的配置
$ npm config list -l
# 查看当前npm cache和prefix路径
$ npm config get cache
$ npm config get prefix
# 修改缓存路径
$ npm config set cache "D:\Program Files\nodejs\npmCache"
# 修改全局下载路径
$ npm config set prefix "D:\Program Files\nodejs\npmGlobal"
# 临时使用
$ npm --registry https://registry.npm.taobao.org install express
# 长期使用
$ npm config set registry https://registry.npm.taobao.org
$ npm config set registry http://registry.npmmirror.com
# 配置后可通过下面方式来验证是否成功
npm config get registry
或
$ npm info express
# 通过cnpm使用
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
// 还原默认的npm配置
$ npm config set registry https://registry.npmjs.org
install 安装模块
# 读取package.json里面的配置单安装
$ npm install
//可简写成 npm i
# 默认安装指定模块的最新(@latest)版本
$ npm install [<@scope>/]<name>
//eg:npm install gulp
# 安装指定模块的指定版本
$ npm install [<@scope>/]<name>@<version>
//eg: npm install gulp@3.9.1
# 安装指定指定版本范围内的模块
$ npm install [<@scope>/]<name>@<version range>
//eg: npm install vue@">=1.0.28 < 2.0.0"
# 安装指定模块的指定标签 默认值为(@latest)
$ npm install [<@scope>/]<name>@<tag>
//eg:npm install sax@0.1.1
# 通过Github代码库地址安装
$ npm install <tarball url>
//eg:npm install git://github.com/package/path.git
uninstall 卸载模块
#卸载当前项目或全局模块
$ npm uninstall
eg: npm uninstall gulp --save-dev
npm i gulp -g
# 卸载后,你可以到 /node\_modules/ 目录下查看包是否还存在,或者使用以下命令查看:
$ npm ls #查看安装的模块
#升级当前项目或全局的指定模块
$ npm update
//eg: npm update express
npm update express -g
$ npm cache clean --force
# 引用依赖 有些包是全局安装了,在项目里面只需要引用即可。
$ npm link [<@scope>/]
//eg: 引用 npm link gulp gulp-ssh gulp-ftp
//eg: 解除引用 npm unlink gulp
# 引用模块 本人用得少没深入说了 用得上时可去翻文档例子
$ npm link (in package dir)
# 未注册 申请注册一个用户 直接在https://www.npmjs.com/注册一样
$ npm adduser
//执行后 填写几个问题 Username、Password、Email
#已注册
$ npm login
#发布
$ npm publish
本站所发布的一切软件资源、文章内容、页面内容可能整理来自于互联网,在此郑重声明本站仅限用于学习和研究目的;并告知用户不得将上述内容用于商业或者非法用途,否则一切后果请用户自负。
如果本站相关内容有侵犯到您的合法权益,请仔细阅读本站公布的投诉指引页相关内容联系我,依法依规进行处理!
作者:理想
链接:https://www.imyjs.cn/archives/shuoshuo/npm%e5%b8%b8%e7%94%a8%e5%91%bd%e4%bb%a4
共有 0 条评论