Nodejs installation and configuration environment

Transfer: https://www.jianshu.com/p/13f45e24b1de

 

1, download the installation package

Download: https://nodejs.org/zh-cn/download/

According to their own computer systems and median selection, I chose windows64 bit .msi installation package format here

.msi and .zip format differences:

1, .msi is the Windows installer developed program installation files, it allows you to install, modify, uninstall programs you have installed. To put it plainly .msi is the Windows installer packets, all the installation files and relevant content packaged in a bag.

2, .zip is a compressed packet, can, after decompression need to install


 

image.png

After the download is complete, double-click the installation package to start the installation, has been point next to the installation path by default in the C: \ Program Files, you can also custom modifications


 

image.png


 

image.png

Node.js runtime indicates the operating environment

npm package manager npm represent Package Manager

Online documentation online documentation shortcuts shortcuts

Add to PATH environment variable to add

As shown installed, where I modified the C node of the installation path: \ node


 

After installation, the installation package .msi format has been added to the node launcher system environment variable path, review verification system variables


 

image.png

Now that the program has been added to the global system variable node, we can directly execute node anywhere in the CMD window, open the CMD window, execute the command node -v view node version


 

image.png

The latest version of the node during installation is also npm install, execute npm npm -v View version


 

image.png

2, modification package path

By default, when we execute npm install -g XXXX, download a global package, this package is the default storage path bit of C: \ Users \ Administrator \ AppData \ Roaming \ npm \ node_modules, can npm root by CMD command - g View


 

image.png


 

image.png

We can try to download a global package, execute the command npm install -g express


 

image.png


 

image.png

But sometimes we do not want a global package on here, we want to put the installation directory node

1, in the node installation directory under the new two folders

node_global global package download store

node_cachenode Cache


 

image.png

2, modify the path

Perform the following two commands in the CMD window:

npm configsetprefix"C:\node\node_global"

npm config set cache "C:\node\node_cache"

Or find node_modules \ npm \ .npmrc file in the installation directory nodejs, the amended as follows:

prefix =C:\node\node_global

cache = C: \ node \ node_cache


 

image.png

Once again, we download a global package, execute the command npm install -g vue, can be found, downloaded vue global package has been placed in the directory we set


 

image.png

We wrote a js file, the introduction of vue module, and outputs the js file and then re-execute the node


 

image.png

We changed the storage path and cache path npm global module, in which case the above error will occur when using the module, because the computer system you do not know the default path to change, and so it is necessary to modify the system environment variables.

1, modify the user variables path is: C: \ node \ node_global


 

image.png


 

image.png

2, NODE_PATH System variables, the variable value C: \ node \ node_global \ node_modules


 

image.png

Close CMD window after the changes, and then reopen it, just run the file test.js


 

image.png

Guess you like

Origin www.cnblogs.com/feiye512/p/12539306.html