Node.js installation and configuration

This article first appeared on the side of technology blog Yujie

Please indicate the source

Download and install

1, go to official website to download the corresponding system installation package

2, proposed to amend the installation directory is not recommended on the C drive, all the way to the default installation when you install

3. After the installation is complete, start a command-line tool, the input node -v and npm -v view the installed version, the version information appears is the prompt successful installation

Environment Configuration

Here the main path is configured npm installed global module is located, and the path of the buffer cache.

Because after performing similar: When [npm install -g] module name of the installation statement, will install the module to [C: \ Users \ username \ AppData \ Roaming \ npm] path, it takes up too much disk space C.

I will nodejs installed in [D: \ nodejs] directory, the following can be adjusted according to the corresponding installation directory:

1, in the installation directory [D: \ nodejs] in the new two folders node_global (global package store directory) and node_cache (cache directory)

2. Open a command prompt (cmd) Tools, and then execute the following two commands:

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

3, configure the environment variables:

[Open System Properties - Advanced - Environment variables], the system variables, [New] a system variable:

  • Variable name: [] NODE_PATH
  • Variable values: [D: \ nodejs \ node_global \ node_modules] (the value of the variable here, please replace it with your own path, you may want to ask: I do not node_modules node_global folder inside the folder ah, how to fill out here the answer is?: We do not need him, back when installing the module, he creates node_modules folder!)

PATH edit user variables, the default [C: \ Users \ blue \ AppData \ Roaming \ npm] modified as [D: \ nodejs \ node_global]

In this way, these two environment variables configured, followed by OK to point

Use Taobao NPM mirror

As the domestic network environment restrictions when using npm install packages, experience a long time, even a failed installation, it is recommended to use Taobao mirroring, specific method, see the official website

Using official recommended cnpm command-line tool instead of the default npm:

npm install -g cnpm --registry=https://registry.npm.taobao.org

Here you can use the [cnpm install the module name] -g command to install the module, and if you install a express:

cnpm install express -g

It can be seen at this time express been installed successfully, and fast!

other

Sometimes the path when installing the module with cnpm there may be a problem, cause problems when using the react-native application development. At this point you can switch back to using nrm official source:

npx nrm use npm

If you think Taobao to switch back to the source, you can enter the following command:

npx nrm use taobao
Released six original articles · won praise 27 · views 4820

Guess you like

Origin blog.csdn.net/weixin_41978102/article/details/105249461