Recently, when doing small program development, cloud function is useful, and cloud function is to use node.js Therefore, it is inevitable to use some node class libraries. To use the node library, you must install it on the computer node.js Environment, and configure the environment variables of NPM command. With the Mac computer, these are basically self-contained, do not need to install and configure. But most students are windows computers, so today I will teach you how to install them on Windows computers node.js And configure the NPM command
1、 Download node package
It is recommended that you download it directly from the official website: https://nodejs.org/zh-cn/download/
2、 Install node package
1. After downloading, double-click to install, and then click next as shown in the figure below
2. Accept the agreement and click next
3. Install the directory, and then click next
The installation directory here must be kept in mind, which will be used later.
|Node.js runtime||Represents the running environment|
|npm package manager||Represents the NPM package manager|
|online documentation shortcuts||Online document shortcut|
|Add to PATH||Add to environment variable|
Leave all of them by default and click next
5. You can click next without checking here
6. Click Install
Then wait for the installation
7. After installation, click finish
3、 Verify installation
Win + R shortcut key calls up the following figure
Enter CMD and press enter to enter the DOS command line.
Enter node – V. if the following figure appears, the installation is successful
Then entering NPM – V usually results in the following error
This means that our NPM global environment variables are not configured. Next, we will teach you how to configure NPM environment variables.
4、 Configuration of NPM environment variables
1. Configure environment variables
My computer > right click > Properties > Advanced System Settings > Advanced > environment variables
2. Click path, and then click Edit
3. Add our node installation directory to the path, and separate it with; in front of it
After setting, don’t forget to click OK.
4, and then win + R – > CML – > Open DOS command line again, and enter NPM – V
As shown in the figure above, if the version number appears, it means that the configuration of NPM global environment variables is completed.
5、 (optional) allocate to another disk
Say the important thing three times: there can be no configuration here, there can be no configuration, this step is not necessary
Again, in fact, the first four steps have already met our needs, and the fifth step can be configured.
The reason why I wrote it is that all the node class libraries will be downloaded to Disk C by default. It can be seen from NPM root – G. My node class libraries all exist on disk C. Sometimes the window computer stores too many things in the C disk, which will affect the speed of the computer. So I decided to store the node Library in my disk.
1. First, configure and create two files in the installation directory of disk D node, as shown in the figure below
Remember point 3 of step 2 above, as shown below. I choose the node in the install directory of disk D.
2, and then order
npm config set prefix "D:\install\node\node_global" npm config set cache "D:\install\node\node_cache"
Note: here, D: install node is my node installation directory. You need to replace it with your own.
After execution, enter NPM root – G to see that our directory has changed
3. Set D:_ Global is configured to the path of the environment variable, as shown in the following figure
We want to install the class library like request
You can see our d: Install / node / node_ The request class library has been successfully installed in the global directory
In this way, the class library that we download in the future will be directly saved to disk D, which will not occupy disk space