Home > Web Front-end > Front-end Q&A > How to install Node.js to the D drive and set the npm source to Taobao mirror

How to install Node.js to the D drive and set the npm source to Taobao mirror

PHPz
Release: 2023-04-06 09:38:20
Original
1167 people have browsed it

Node.js is a JavaScript runtime based on the Chrome V8 engine for building efficient web applications. It uses an event-driven, non-blocking I/O model and is widely used in fields such as web servers and command line tools.

Although Node.js provides a cross-platform executable file installation package, we usually install Node.js under a specific drive letter and path to facilitate management and maintenance. The following are the specific steps and precautions for installing Node.js to the D drive and setting the npm source to the Taobao image.

Step 1. Download Node.js

First, we need to download the corresponding version of the installation package from the Node.js official website, the address is https://nodejs.org/zh- cn/. On this page, we can see the latest LTS version and the latest stable version, and choose a version to download according to your needs.

Step 2. Install Node.js

After downloading, double-click the downloaded exe installation package and follow the prompts to install. During the installation process, you can choose to install Node.js to any drive letter and path. In this example, we choose to install it to the root directory of the D drive.

Step 3. Configure environment variables

After the installation is completed, you need to configure the Node.js environment variables so that the Node.js program can be run in any directory. The specific steps are as follows:

1. Open the command prompt (CMD) and execute the following command to view the installation path of Node.js:

where node
Copy after login

2. Add the path output by the above command to the system environment in the variable Path. Open "My Computer"->"Properties"->"Advanced System Settings"->"Environment Variables", double-click "Path", and add the installation path of Node.js in the input box (use separate paths for multiple paths) separated by ";").

3. In the same environment variable page, click the "New" button and add an environment variable named "NODE_PATH" with a value of "Installation Directory\node_modules", where "Installation Directory" is your Node.js installation path.

4. Save the environment variables and close all command prompt windows.

Step 4. Install Taobao image

Node.js official npm package manager will connect to the official npm source by default. But the download speed in China is very slow, so we need to switch it to a domestic mirror, such as Taobao mirror. The specific steps are as follows:

1. Open the command prompt (CMD) and execute the following command to install the Taobao image:

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

2. Execute the following command to switch the npm source to the Taobao image:

npm config set registry https://registry.npm.taobao.org
Copy after login

At this point, Node.js has been successfully installed on the D drive, and the Taobao image has been set as the default npm source. We can check whether the installation is successful by executing the following command:

node -v
npm -v
Copy after login

If the version numbers of Node.js and npm are output, the installation is successful.

Summary

Through the above steps, we can install Node.js to a specific drive letter and path, and configure the Taobao image as the default source of npm. This can greatly improve the download speed of Node.js modules and improve the efficiency of project development.

The above is the detailed content of How to install Node.js to the D drive and set the npm source to Taobao mirror. For more information, please follow other related articles on the PHP Chinese website!

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