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默认配置

  1. #npm config ls -l

  2. ; cli configs

  3. long = true

  4. user-agent = "npm/2.14.12 node/v4.2.4 win32 x64"

  5. ; builtin config undefined

  6. prefix = "C:\\Users\\zgr\\AppData\\Roaming\\npm"

  7. registry = "https://registry.npm.taobao.org/"

  8. ; default values

  9. access = null

  10. always-auth = false

  11. bin-links = true

  12. browser = null

  13. ca = null

  14. cache = "C:\\Users\\zgr\\AppData\\Roaming\\npm-cache"

  15. cache-lock-retries = 10

  16. cache-lock-stale = 60000

  17. cache-lock-wait = 10000

  18. cache-max = null

  19. cache-min = 10

  20. cafile = undefined

  21. cert = null

  22. color = true

  23. depth = null

  24. description = true

  25. dev = false

  26. editor = "notepad.exe"

  27. engine-strict = false

  28. fetch-retries = 2

  29. fetch-retry-factor = 10

  30. fetch-retry-maxtimeout = 60000

  31. fetch-retry-mintimeout = 10000

  32. force = false

  33. git = "git"

  34. git-tag-version = true

  35. global = false

  36. globalconfig = "C:\\Users\\zgr\\AppData\\Roaming\\npm\\etc\\npmrc"

  37. globalignorefile = "C:\\Users\\zgr\\AppData\\Roaming\\npm\\etc\\npmignore"

  38. group = 0

  39. heading = "npm"

  40. https-proxy = null

  41. if-present = false

  42. ignore-scripts = false

  43. init-author-email = ""

  44. init-author-name = ""

  45. init-author-url = ""

  46. init-license = "ISC"

  47. init-module = "C:\\Users\\zgr\\.npm-init.js"

  48. init-version = "1.0.0"

  49. json = false

  50. key = null

  51. link = false

  52. local-address = undefined

  53. loglevel = "warn"

  54. ; long = false (overridden)

  55. message = "%s"

  56. node-version = "4.2.4"

  57. npat = false

  58. onload-script = null

  59. optional = true

  60. parseable = false

  61. ; prefix = "C:\\Program Files\\nodejs" (overridden)

  62. production = false

  63. proprietary-attribs = true

  64. proxy = null

  65. rebuild-bundle = true

  66. ; registry = "https://registry.npmjs.org/" (overridden)

  67. rollback = true

  68. save = false

  69. save-bundle = false

  70. save-dev = false

  71. save-exact = false

  72. save-optional = false

  73. save-prefix = "^"

  74. scope = ""

  75. searchexclude = null

  76. searchopts = ""

  77. searchsort = "name"

  78. shell = "C:\\Windows\\system32\\cmd.exe"

  79. shrinkwrap = true

  80. sign-git-tag = false

  81. spin = true

  82. strict-ssl = true

  83. tag = "latest"

  84. tag-version-prefix = "v"

  85. tmp = "C:\\Users\\zgr\\AppData\\Local\\Temp"

  86. umask = 0

  87. unicode = true

  88. unsafe-perm = true

  89. usage = false

  90. user = 0

  91. ; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overri

  92. dden)

  93. userconfig = "C:\\Users\\zgr\\.npmrc"

  94. version = false

  95. versions = false

  96. viewer = "browser"

2.4 设置全局安装目录

npm config set cache "D:\nodejs\node_cache"

npm config set prefix "D:\nodejs\node_global"

然后就可以愉快的使用cnpm安装工具了

3 常用命令集合

  1. node -v #查看安装版本

  2. npm -v #查看npm安装版本

  3. npm config ls -l #查看配置项