【Tools official website】
Node.js : http://nodejs.cn/
Taobao NPM: https://npm.taobao.org/
【installation steps】
1. Install node.js
1. Go to the node.js official website to download and install the tool, here the installation path is selected to D drive, D:\Program Files\nodejs
After the installation is complete, enter the following command on the command line to test whether the installation is successful, and the version number will appear correctly
1
|
npm -v
|
2. Change the original environment variables,
(1) We need to configure the storage path of the global module of npm and the path of the cache. For example, if I want to put the above two folders in the main directory of NodeJS, I will create two "node_global" and "node_cache" under NodeJs. folder, enter the following command to change the npm configuration
1
2
|
npm config
set
prefix
"C:\Program Files\nodejs\node_global"
npm config
set
cache
"C:\Program Files\nodejs\node_cache"
|
(2) Add the system variable NODE_PATH to the system environment variable, enter the path D :\Program Files\nodejs\node_global\node_modules, and the modules installed after that will be installed in the changed path
(3) Enter the following command on the command line to try to install express (Note: the parameter "-g" means to install it in the global directory, that is, in the " D:\Program Files\nodejs\node_global " set above. )
1
|
npm install express -g
|
After installation, you can see. \node_global\node_modules\express already has content
(4) Enter node on the command line to enter the editing mode, and enter the following code to test whether the module can be loaded normally:
1
|
require(
'express'
)
|
假设成功,可以看到有输出。假设出错,检查NODE_PATH的路径。
二、安装淘宝npm(cnpm)
1.安装cnpm
(1)输入以下命令
1
|
npm install -g cnpm --registry=https:
//registry.npm.taobao.org
|
(2)输入cnpm -v输入是否正常,这里肯定会出错。
1
|
cnpm -v
|
(3)添加系统变量path的内容
因为cnpm会被安装到D:\Program Files\nodejs\node_global下,而系统变量path并未包含该路径。在系统变量path下添加该路径即可正常使用cnpm。