Node.js Installation and Environment Configuration for Windows

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:

Fourth, start the installation

1. After the download is complete, double-click "node-v6.9.2-x64.msi" to start installing Node.js


Click the [Next] button


Check the box and click the [Next] button


After modifying the directory, click the [Next] button


After installation, click the [Finish] button to complete the installation

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.

The directory after installation is as shown below:

此处说明下:新版的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】如下图:

创建完两个空文件夹之后,打开cmd命令窗口,输入

npm config set prefix "D:\Develop\nodejs\node_global"
npm config set cache "D:\Develop\nodejs\node_cache"

接下来设置环境变量,关闭cmd窗口,“我的电脑”-右键-“属性”-“高级系统设置”-“高级”-“环境变量”

进入环境变量对话框,在【系统变量】下新建【NODE_PATH】,输入【D:\Develop\nodejs\node_global\node_modules】,将【用户变量】下的【Path】修改为【D:\Develop\nodejs\node_global】


六、测试

配置完后,安装个module测试下,我们就安装最常用的express模块,打开cmd窗口,
输入如下命令进行模块的全局安装:

npm install express -g     # -g是全局安装的意思

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325709855&siteId=291194637