nodeJS设置淘宝镜像
node.js安装
下载node.js安装包:https://nodejs.org/en/download/,下载相应版本的node.js.
需注意,在window中,node的安装目录中,最好不要有空格或中文字符。
nodeJS的资源仓库在国内使用过程中,偶尔会遇到各种资源问题,通常设置为淘宝的镜像,网上很多说法是安装淘宝镜像,即
$ npm install -g cnpm --registry=https://registry.npm.taobao.org
然后再用到npm install的时候,使用cnpm install进行安装node_modules。
但是该种方式,在集成到IED的时候,你如在IDEA中,如果想在IDEA中,直接使用node的命令,进行install,就行不通了。这个时候,可以使用第二种方式:
npm config set registry " https://registry.npm.taobao.org "
更改npm的config的registry 为淘宝镜像,然后再使用npm的时候,就是从淘宝镜像拉取数据了。
在更新node-sass中,有时候也会出现资源下载不了的问题,通常是git上的资源下载不了,这时候,可以更改node-sass的资源路径为淘宝的
npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
phantomjs的源
npm config set phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
electron源
npm config set electron_mirror=https://npm.taobao.org/mirrors/electron/
2.3 查看Nodejs默认配置
#npm config ls -l
; cli configs
long = true
user-agent = "npm/2.14.12 node/v4.2.4 win32 x64"
; builtin config undefined
prefix = "C:\\Users\\zgr\\AppData\\Roaming\\npm"
registry = "https://registry.npm.taobao.org/"
; default values
access = null
always-auth = false
bin-links = true
browser = null
ca = null
cache = "C:\\Users\\zgr\\AppData\\Roaming\\npm-cache"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
color = true
depth = null
description = true
dev = false
editor = "notepad.exe"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
global = false
globalconfig = "C:\\Users\\zgr\\AppData\\Roaming\\npm\\etc\\npmrc"
globalignorefile = "C:\\Users\\zgr\\AppData\\Roaming\\npm\\etc\\npmignore"
group = 0
heading = "npm"
https-proxy = null
if-present = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "C:\\Users\\zgr\\.npm-init.js"
init-version = "1.0.0"
json = false
key = null
link = false
local-address = undefined
loglevel = "warn"
; long = false (overridden)
message = "%s"
node-version = "4.2.4"
npat = false
onload-script = null
optional = true
parseable = false
; prefix = "C:\\Program Files\\nodejs" (overridden)
production = false
proprietary-attribs = true
proxy = null
rebuild-bundle = true
; registry = "https://registry.npmjs.org/" (overridden)
rollback = true
save = false
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
scope = ""
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "C:\\Windows\\system32\\cmd.exe"
shrinkwrap = true
sign-git-tag = false
spin = true
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
tmp = "C:\\Users\\zgr\\AppData\\Local\\Temp"
umask = 0
unicode = true
unsafe-perm = true
usage = false
user = 0
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overri
dden)
userconfig = "C:\\Users\\zgr\\.npmrc"
version = false
versions = false
viewer = "browser"
2.4 设置全局安装目录
npm config set cache "D:\nodejs\node_cache"
npm config set prefix "D:\nodejs\node_global"
然后就可以愉快的使用cnpm安装工具了
3 常用命令集合
node -v #查看安装版本
npm -v #查看npm安装版本
npm config ls -l #查看配置项