npm使用
【摘要】 npm使用
npm使用
淘宝镜像(更新于2024-06-11)强烈建议直接使用官网镜像(更新于2025-08-29)
🍎快捷签
https://registry.npmjs.org/
//查看镜像地址
npm config get registry
//设置官方地址
npm config set registry https://registry.npmjs.org/
// 设置镜像地址
npm config set registry http://registry.npmmirror.com
1、认识
npm概念
npm是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种:
- 允许用户从NPM服务器下载别人编写的第三方包到本地使用。
- 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
- 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。
镜像地址 2024-06-11
# 查看npm版本
npm -v
# 查看npm镜像地址
npm config get registry
# 设置为国内的镜像
//切换新源
npm config set registry https://registry.npmmirror.com
# 官方最新迁移镜像地址 (永久替换 2021-04-18 留言)
(永久替换 2024-06-11 留言---下面的地址是官方稳定长期镜像版本)
npm config set registry http://registry.npmmirror.com
下面的地址是官方地址
npm config set registry https://registry.npmjs.org/
2、常用命令
使用npm时网络环境较差,所以备用
2-1 常用命令
# 检测npm安装的版本号
npm -v
# 查询当前镜像源
npm get registry
# 清空缓存
npm cache clean --force
# 删除项目下的node_modules文件夹
npm uninstall
# 安装依赖
npm install
# 忽略依赖安装
npm install with --force
# 忽略依赖冲突安装
npm install --legacy-peer-deps
2-2 查看本地npm配置的仓库镜像
npm get registry
# 查询当前镜像源
npm config get registry
2-3 旧版本的npm通过npm命令来升级
npm install npm -g
2-4 设置为淘宝镜像(废弃)
- 设置本次从淘宝镜像上安装的包不改变npm原有的仓库镜像源 (单次npm使用淘宝镜像)
npm install --registry=https://registry.npm.taobao.org
- 设置为淘宝镜像 (废弃)
npm config set registry http://registry.npm.taobao.org/
(永久替换 2024-06-11 留言---下面的地址是官方稳定长期镜像版本)
npm config set registry http://registry.npmmirror.com
设置回默认的官方镜像
npm config set registry https://registry.npmjs.org/
设置electron淘宝镜像
npm config set ELECTRON_MIRROR "https://npm.taobao.org/mirrors/electron/"
查看和删除electron淘宝镜像设置:
npm config get ELECTRON_MIRROR
npm config delete ELECTRON_MIRROR
2-5 本地npm的仓库镜像源配置(废弃)
配置本地npm的仓库镜像源地址,以后下载包,在下载命令中不配置镜像源时,就从上述配置的镜像源中下载指定的安装包
npm config set registry <https://....仓库镜像源地址>
registry = https://registry.npm.taobao.org
2-6 使用cnpm命令替换npm命令
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install npm@7.18.1 -g // 利用cnpm安装指定版本
3、npm 使用
3-1 查看所有全局安装的包
npm -g list
3-2 卸载某个包;卸载所有的包
npm uninstall <包名> ; npm uninstall *
3-3 查看依赖包
npm ls
3-4 清除缓存
npm cache verify
或者
npm cache clean --force
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)