Modify the global path of npm installation and the pit for configuring environment variables

Reprinted from: http://www.qdfuns.com/notes/30749/0f66fcf5e62eed010f744d0d4adaa870.html

When I installed npm before, it was all installed by default, and the modules were all installed on the C drive. Today, I changed the path to the D drive on a whim. After the change, the modules could not be recognized, and they all prompted that the XX module is not an internal command. This is actually the environment. Regarding the problem of variable configuration, I changed the environment variables according to the online tutorials, but there were mistakes in changing them. The steps are as follows:
1. To create two folders in the folder where you need to store the modules, I created two folders called node_global and node_cache in the node directory.
2. Modify the npmrc file under the npm folder, open and modify the content, delete the original content, and write
prefix=D:\node\node_global
cache=D:\node\node_cache
This is the path to configure the installation module as a step A newly created folder. Then you can find any module and install it. The module will appear in the node_global folder.
3. After the module is installed, it cannot be used. Because the default path has been changed, it is necessary to modify the environment variable configuration of the system to allow the command line to recognize the command, which is divided into user variables and system variables. First create a variable named PATH in the user variable, the value is D:\node\node_global, this value is the path of the new folder you created in the step. Then create a new variable called NODE_PATH in the system variable, the value is D:\node\node_global\node_modules, this value is the path of the node_modules folder under the node_global newly created in step 1, the global modules installed in the future are here, ( This folder will only appear after installing any module, so you need to install a module before configuring the environment variables)
4. Finally, about cnpm, I don't want to use it now. I have encountered unsuccessful installations with it before. Now I have changed the default address and installed it, but I can't use it. Fortunately, there are other ways. It's a simple sentence: npm config set registry https://registry.npm.taobao.org This sentence can set npm to download and install modules from the domestic Taobao mirror.
Summary: Why set user variables in the third step? I later found that there is a file called XXX.cmd in this path, which is the name of the module you installed before + cmd. This cmd file should be recognized by the user after entering the name of the module, so that XX is not an internal command. I tried it Deliberately set the wrong user's path and then prompt that it is not an internal command. The node_path should be recognized by the node program when it finds the module by itself. All of the above are my own personal understanding, for reference only, not necessarily useful to everyone, because I refer to others, it does not work for me.

Guess you like

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