nodejs和npm安装与系统环境变量配置及国内加速
下载node-v22.14.0-x64.msi
建议修改为非C盘文件夹
其它步骤,下一步,下一步,完成。
打开CMD窗口查看安装详情
$ node -v
v22.14.0
$ npm -v
10.9.2$ npm config list
创建node_global
和node_cache
目录
D:
mkdir node_global
mkdir node_cache
npm config set prefix D:\node_global
npm config set cache D:\node_cache
此电脑–单击右键—属性–高级–系统设置–环境变量
在系统变量添加
变量名:NODE_PATH
变量值:D:\node_global\node_modules
在用户变量修改path变量
# 修改前
C:\Users\username\AppData\Roaming\npm
# 修改后
D:\node_global
配置完后,安装个module测试下,我们就安装最常用的express模块,打开cmd窗口,
输入如下命令进行模块的全局安装:
npm install express -g # -g是全局安装的意思
输入tree D:\node_global
查看
└─node_modules└─express├─lib│ ├─middleware│ └─router└─node_modules├─.bin├─accepts├─array-flatten├─body-parser│ └─lib│ └─types
使用以下命令将npm的默认registry设置为淘宝镜像源。
npm config set registry https://registry.npmmirror.com
参考资料
npm config
$ npm config -h
Manage the npm configuration filesUsage:
npm config set <key>=<value> [<key>=<value> ...]
npm config get [<key> [<key> ...]]
npm config delete <key> [<key> ...]
npm config list [--json]
npm config edit
npm config fix
bun安装
npm install -g bun
pnpm安装
npm install -g pnpm
pnpm config list