have been ready to start learning Nodejs, but have to say that Nodejs installation and configuration on Windows is a pit.
In particular, the configuration of the module location in NPM.
Okay, nonsense. Don't say much, first download the Nodejs version.
Then you can install it all the way next, where you choose your own installation path. I am here to install under D:\nodejs.
After the installation is complete, enter it on the command line:
Node-v
Npm-v
The following output appears even if the installation was successful.
The next problem is that if you use NPM to install the module directly, it will install your module under the AppData of the C drive to ensure that it can be used globally.
In this case, it is inconvenient to manage. So I want to put it directly in the Nodejs installation directory, and can guarantee the global use, how to do?
Go to 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: It is important to note that the cursor has been flashing after NPM, but there is no response, if NPM had previously failed with set prefix. then you can go to the C-disk C:\Users\Administrator directory (I am the Admin user), modify the. npmrc file, or delete it, then everything is OK.
Of course, you first need to manually build the Node_global and Node_cache directories below the Nodejs.
Node_global is used to store the modules you download, the Node_cache directory is the cache.
After that you're using the NPM Install module name-G
Then your downloaded module will be saved in the Node_global, and will not be saved in the C-drive under the AppData.
And then there's a problem that needs to be addressed.
Now the module is saved, but we can't find the module when we need to require it.
Here, you need to configure the environment variable Node_path.
Add Node_path to the system variable, environment variable, advanced system configuration, properties---, my computer.
Then type in your Node_global path.
The main path here is to take the node_modules.
For example, my global directory is
D:\nodejs\node_global
So here's my node_path configured as
D:\nodejs\node_global\node_mudules
Here you can install the Express module test first
NPM Install Express-g
After waiting for the cursor to turn, you can see the Express directory in the Node_mudules in Node_global,
This proves that the EXPRSS installation is successful and the location is correct.
After the configuration node_path after the cmd command line, enter the command, the following interface appears, which indicates the successful acquisition of the Express module, configured correctly.
Nodejs tread on the pit, to record it, beware of forgetting.
[NodeJS] NodeJS is configured with NPM (Node Pagkage manager).