文章目录
NodeJS安装及全局配置
下载nodeJS
首先我们要到nodejs官网(https://nodejs.org)上下载node
查看版本
> node -v
v12.16.1
> npm -v
6.13.4
查看全局配置
> npm config ls
; cli configs
metrics-registry = "https://registry.npm.taobao.org/"
scope = ""
user-agent = "npm/6.13.4 node/v12.16.1 win32 x64"
; userconfig C:\Users\Administrator\.npmrc
cache = "D:\\Develop\\node-all-win-x64\\node_cache"
prefix = "D:\\Develop\\node-all-win-x64\\node_global"
registry = "https://registry.npm.taobao.org/"
registy = "https://registry.npm.taobao.org"
; node bin location = D:\Develop\node-v12.16.1-win-x64\node.exe
; cwd = C:\Users\Administrator
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.
通过命令修改presfix和cache
进入cmd命令行,输入一下的命令设置全局模块的安装路径到node_global文件夹,缓存到node_cache文件夹:
> npm config set prefix "D:\Develop\nodejs\node_global"
> npm config set cache "D:\Develop\nodejs\node_cache"
换源
国内优秀npm镜像
淘宝npm镜像
- 搜索地址:http://npm.taobao.org/
- registry地址:http://registry.npm.taobao.org/
cnpmjs镜像
- 搜索地址:http://cnpmjs.org/
- registry地址:http://r.cnpmjs.org/
使用源
临时使用
npm --registry https://registry.npm.taobao.org install express
持久使用
# 设置淘宝源
npm config set registry https://registry.npm.taobao.org
# 设置官方源
npm config set registry https://registry.npmjs.org/
disturl
# 淘宝
https://npm.taobao.org/dist
# 官方
https://nodejs.org/dist/
npm config set disturl https://nodejs.org/dist
node-sass/phantomjs/electron使用淘宝镜像站
有些软件包安装的时候会下载已预编译好的二进制格式,比如node-sass
/phantomjs
/electron
等等,这几个软件包大多数都将编译好的成品托管在S3上。
比较幸运的是这些软件包都有办法指定下载的路径,有兴趣的可以自己去读这些包的安装代码,会去从环境变量或npmrc配置中读取下载的路径,这里只贴出npmrc
方案。同样也适用于npm环境变量配置方案:
npm config set registry https://registry.npm.taobao.org/
npm config set disturl https://npm.taobao.org/dist/
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/
npm config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver/
npm config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver/
npm config set python_mirror https://npm.taobao.org/mirrors/python/
npm config set electron_builder_binaries_mirror https://npm.taobao.org/mirrors/electron-builder-binaries/
npm config set node_sqlite3_binary_host_mirror https://npm.taobao.org/mirrors
on-builder-binaries/
npm config set node_sqlite3_binary_host_mirror https://npm.taobao.org/mirrors