1. Installation environment
1. Native system: Windows 10 Pro (64-bit)
2. Node.js: v6.9.2LTS (64-bit)
Second, install Node.js steps
1. Download the Node.js version corresponding to your system: https://nodejs.org/en/download/
2. Select the installation directory for installation
3. Environment configuration
4. Test
3. Preliminary preparation
1. Introduction to Node.js
Simply put, Node.js is JavaScript running on the server side. Node.js is a JavaScript runtime environment based on the Chrome V8 engine. Node.js uses an event-driven, non-blocking I/O model, making it lightweight and efficient. npm , the package manager for Node.js , is the world's largest ecosystem of open source libraries.
2. Download Node.js
Open the official website download link: https://nodejs.org/en/download/ I downloaded node-v6.9.2-x64.msi here, as shown below:
![](https://upload-images.jianshu.io/upload_images/2267589-bb1555667d5355af.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Fourth, start the installation
1. After the download is complete, double-click "node-v6.9.2-x64.msi" to start installing Node.js
![](https://upload-images.jianshu.io/upload_images/2267589-131af95ee6ebc811.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Click the [Next] button
![](https://upload-images.jianshu.io/upload_images/2267589-69648c7b8aa496fe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Check the box and click the [Next] button
![](https://upload-images.jianshu.io/upload_images/2267589-b87cc08121e1c880.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
After modifying the directory, click the [Next] button
![](https://upload-images.jianshu.io/upload_images/2267589-f40b21a6ccbebefa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/2267589-3a9b3706c81fb5fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
After installation, click the [Finish] button to complete the installation
![](https://upload-images.jianshu.io/upload_images/2267589-adca4baa7f0d7190.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
So far Node.js has been installed, you can first perform a simple test to see if the installation is successful, and then configure
the environment. Press the [win+R] key on the keyboard, enter cmd, and then press Enter to open the cmd window.
![](https://upload-images.jianshu.io/upload_images/2267589-19531194e378a38a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/2267589-2c9ced41baca7c1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
The directory after installation is as shown below:
![](https://upload-images.jianshu.io/upload_images/2267589-261e36d32bc47133.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
此处说明下:新版的Node.js已自带npm,安装Node.js时会一起安装,npm的作用就是对Node.js依赖的包进行管理,也可以理解为用来安装/卸载Node.js需要装的东西
常规NodeJS的搭建到现在为止已经完成了,急不及待的话你可以在”cmd“输入”node“进入node开发模式下,输入你的NodeJS第一句:”hello world“ - 输入:console.log('hello world')。
五、环境配置
说明:这里的环境配置主要配置的是npm安装的全局模块所在的路径,以及缓存cache的路径,之所以要配置,是因为以后在执行类似:npm install express [-g] (后面的可选参数-g,g代表global全局安装的意思)的安装语句时,会将安装的模块安装到【C:\Users\用户名\AppData\Roaming\npm】路径中,占C盘空间。
例如:我希望将全模块所在路径和缓存路径放在我node.js安装的文件夹中,则在我安装的文件夹【D:\Develop\nodejs】下创建两个文件夹【node_global】及【node_cache】如下图:
![](https://upload-images.jianshu.io/upload_images/2267589-51ed23771f3a86e2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
创建完两个空文件夹之后,打开cmd命令窗口,输入
npm config set prefix "D:\Develop\nodejs\node_global"
npm config set cache "D:\Develop\nodejs\node_cache"
![](https://upload-images.jianshu.io/upload_images/2267589-e22cf1b878275757.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
接下来设置环境变量,关闭cmd窗口,“我的电脑”-右键-“属性”-“高级系统设置”-“高级”-“环境变量”
![](https://upload-images.jianshu.io/upload_images/2267589-7fd332c898799325.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
进入环境变量对话框,在【系统变量】下新建【NODE_PATH】,输入【D:\Develop\nodejs\node_global\node_modules】,将【用户变量】下的【Path】修改为【D:\Develop\nodejs\node_global】
![](https://upload-images.jianshu.io/upload_images/2267589-ca94af8646fab0b4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/2267589-d469f4d79081582a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/2267589-f46d2598f3d53958.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/2267589-3c48768a577428f5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
六、测试
配置完后,安装个module测试下,我们就安装最常用的express模块,打开cmd窗口,
输入如下命令进行模块的全局安装:
npm install express -g # -g是全局安装的意思
![](https://upload-images.jianshu.io/upload_images/2267589-fb7a6e61c1b99541.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)