Home > Web Front-end > JS Tutorial > body text

How to configure the global installation path of Node.js module

php中世界最好的语言
Release: 2018-05-28 15:53:18
Original
1179 people have browsed it

This time I will show you how to configure the global installation path of the Node.js module and configure the global installation path of the Node.js module. What are the precautions? Here is the actual combat Let’s take a look at the case.

After downloading and installing NodeJS, there will be the following files in the path you choose:

By default, NodeJS installation will also install npm (module manager: use There are two modules for managing userrequire, global and local).

Note:

Global: Executing npm install -g will install the module in the global path. When the user requires() in the program, there is no need to consider where the module is. If the global path is not modified, the module downloaded by the user will be in the path C:\Users\Administrator\AppData\Roaming\npm by default. Down.

Partial: Executing npm install (note that -g is missing) will install the module in the path currently pointed to by the dos window. At this time, other path projects cannot reference this version. Module!

Modify the default global path:

First configure the storage path of npm's global module (node_global) and the path of the cache (global_cache). For example, I want to put the above two folders under %nodejs%\node_modules

1) Create "node_global" and "node_global" under D:\apps\nodejs\node_modules\ node_cache" two folders.

2) Execute in the DOS window:

npm config set prefix “D:\apps\nodejs\node_modules\node_global”
npm config set cache “D:\apps\nodejs\node_modules\node_cache”
Copy after login

If this method cannot be modified, you can still do it:

Find node_modules in the nodejs installation directory \npm\.npmrc file

can be modified as follows:

prefix = D:\apps\nodejs\node_modules\node_global
cache = D:\apps\nodejs\node_modules\node_cache
Copy after login

3) At this time, the default global path for npm module installation has been changed to the corresponding folder. , but at this time the user still cannot require these modules, because the computer system still does not know that you have changed the default path, so you need to go to "win R"-->"sysdm.cpl"-->"Advanced"- ->"Environment Variables" opens the settings dialog box.

4) The following is the most critical place (the place that determines the success or failure of the modification!):

① First, in the " system variables ", create a new variable named NODE_PATH. The variable value is: the absolute path of the node_modules folder in the previously created folder used to store global modules. (Tell the system that the global module the user downloaded is here).

That is: D:\apps\nodejs\node_modules\node_global\node_modules

②After creating the new NODE_PATH, you also need to tell the system the locations of node and npm. At this time, you need to set the "Environment Variables" Find the "Path" variable in the "System Variables" column of the dialog box,

Double-click to open it, add an English semicolon ";" at the end of the existing content, and then check whether there is # under the path

##D:\apps\nodejs\; (addresses of node and npm)

The following item needs to be added if cnpm is installed:

D:\apps\nodejs\node_modules\node_global;

(cnpm path, npm install -g cnpm --registry=

https://registry.npm.taobao .org!!!)

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to build a webpack react development environment

How to build a React family bucket environment

The above is the detailed content of How to configure the global installation path of Node.js module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!