npm基本操作手册

查看npm版本

npm -v

设置仓库地址

# 默认仓库地址
npm config set registry https://registry.npmjs.org/
# 淘宝镜像地址
npm config set registry http://registry.npm.taobao.org/
# 指定仓库地址
npm config set registry 如内网仓库地址

# 查看仓库地址
npm config get registry

由于默认仓库地址npmjs.org的服务器在国外(即在“墙”外),国(墙)内开发者做项目的时候,很多“包”的下载速度极慢,在这种环境下阿里巴巴为了众多开发者的便捷便挺身而出推出了淘宝镜像(即cnpm),它把npm官方的“包”全部搬到国内,供广大开发者使用。

从指定仓库下载安装

npm --registry https://registry.npm.taobao.org install

恢复默认仓库地址

npm config delete registry

查看NPM支持的命令

npm -h

查看所有已安装的 npm 软件包

npm list

# 获取顶层的软件包
npm list --depth=0

获取NPM的简要信息

npm config list

全局安装的默认目录

npm config get prefix
npm config set prefix “D:\nodejs\node_global” //设置全局包目录
npm config set cache “D:\nodejs\node_cache” //设置缓存目录

查看程序包的所有版本号

npm view node-sass versions

# 查看最新版本号
npm view node-sass version

查看本地是否安装

npm ls node-sass

# 查看全局是否安装
npm ls node-sass -g

安装模块

npm i 是npm install的简写,它的主要作用是安装Node.js项目的依赖包

# 全局安装模块
npm i 模块名 -g
# 本地安装模块
npm i 模块名
# 全局卸载模块
npm uni -g 模块名(不用加版本号)
# 本地卸载模块
npm uni 模块名(不用加版本号)
# 全局更新模块
npm upd 模块名 -g
#本地更新模块
npm upd 模块名

安装程序包

npm install node-sass

# 从指定淘宝镜像仓库安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org

# 安装最新版本
npm install node-sass@latest

# 安装指定版本
npm install node-sass@4.12.0

# 全局安装
npm install -g lodash

# 通过cnpm安装 vue
cnpm install vue

# 通过cnpm安装vue-cli
cnpm install --global vue-cli

升级程序包

npm update

# 通过cnpm升级npm
cnpm install npm -g

# 通过npm升级cnpm
npm install cnpm -g

# 修复一些问题
npm audit fix --force

卸载程序包

npm uninstall node-sass

npm uninstall -D package-name

npm uninstall --save-dev package-name

//全局卸载
npm uninstall -g cors
posted @ 2024-06-18 14:51  zhαojh  阅读(35)  评论(0编辑  收藏  举报