npm 全局模块的存放路径以及cache的路径的配置,默认是在 C 盘 "C:\Users\用户" 下
-
在 nodejs 安装目录下,创建 ”node_global” 和 ”node_cache” 两个文件夹
-
进入 cmd 命令行,输入如下命令
设置全局模块的安装路径到 "node_global" 文件夹,
设置缓存到 "node_cache" 文件
注意文件夹名称不要有空格,如 Program Files文件夹
npm config set prefix "D:\nodejs\node_global"
npm config set cache "D:\nodejs\node_cache
- 由于 node 全局模块大多数都是可以通过命令行访问的
还要把 “D:\nodejs\node_global” 加入到系统环境变量 PATH 中,方便直接使用命令
- 进入 cmd 命令行, 执行 npm 安装模块
# 配置镜像站
npm config set registry=http://registry.npm.taobao.org
# 检查一下镜像站是否正常
npm config get registry
npm 全局安装方式一 -g
“-g” 表示安装到 global 目录下, 及之前设置的 “D:\nodejs\node_global” 目录