[NodeJS] nodeJS and npm (node pagkage manager) configuration., nodejsnpm

Source: Internet
Author: User

[NodeJS] nodeJS and npm (node pagkage manager) configuration., nodejsnpm

I have been preparing to start learning node. JS, but I have to say that the installation and configuration of node. js on Windows is a pitfall.
In particular, the module position configuration in npm.
Let's talk about it. First, download the nodejs version.
Next, you can install it successfully. You can select your own installation path. I am installing it in d: \ nodejs.
After the installation is complete, enter the following command in the command line:

node -v
npm -v

If the following output is displayed, the installation is successful.

Then, if npm is used directly to install the module, it will install your module under the appdata of drive C to ensure global use.
In this case, management is not convenient. So I want to put it directly under the Nodejs installation directory and ensure global use. What should I do?
Enter the cmd command line and enter the following command

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

Note: Note that if an error occurs due to the use of set prefix before npm, the cursor will flash continuously after npm is input, but there is no response. You can go to the C: \ Users \ Administrator directory of drive C (here I am the admin user), modify the. npmrc file, or delete it. Everything works.

Of course, you must manually create the node_global and node_cache directories under nodejs.
Node_global is used to store the modules you download. The node_cache directory naturally stores the cache.


Then you are using the npm install Module name-g
The downloaded module will be saved in node_global, instead of stored under the appdata of drive C.

There is another problem to be addressed.
Now the module is saved, but the module cannot be found when we need to use require.
Configure the environment variable NODE_PATH.

Choose my computer> Properties> Advanced System Configuration> environment variables> system variables to add NODE_PATH.
Enter your node_global path.
The path here must contain node_modules.
For example, my global directory is

 d:\nodejs\node_global

In this case, my NODE_PATH is configured

d:\nodejs\node_global\node_mudules

Install the express module for testing.

npm install express -g
After the cursor turns, you can view the express directory in node_mudules in node_global,
This proves that exprss is successfully installed and the location is correct.
After configuring NODE_PATH, enter the command in the cmd command line and the following interface appears. This indicates that the express module is successfully obtained and the configuration is correct.


Node. js step on the pitfall to record it, beware of forgetting.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.