When using Node.js, installing dependent packages often requires access to foreign npm official sources. Due to network reasons, the installation package may be very slow or the installation may fail. To do this, we need to set the npm mirror source to a domestic mirror to increase download speed.
1. npm mirror address
Address | Website |
---|---|
cnpmjs.org | http://r.cnpmjs.org |
Alibaba Cloud Mirror | https://developer.aliyun.com /mirror |
Taobao NPM Mirror | https://npm.taobao.org/mirrors/npm |
2. How to modify the npm image
Enter the following command in the terminal:
npm config set registry https://registry.npm.taobao.org
In the above commandhttps://registry.npm.taobao.org
is the Taobao NPM mirror address. Using this address can greatly speed up the download speed of the Node.js module.
If you want to change the set mirror address back to the default official address, you can enter the following command:
npm config set registry https://registry.npmjs.org
in the command line window Execute the following command to install cnpm:
npm install -g cnpm --registry=https://registry.npm.taobao.org
As mentioned above, the --registry=https://registry.npm.taobao.org
parameter indicates using the Taobao NPM mirror source for installation. When using cnpm to install the module, no other settings are required. Just use cnpm install
to automatically use the Taobao NPM mirror source.
3. How to check the npm mirror address
Enter the following command in the command line:
npm config get registry
The current npm mirror address will be output:
https://registry.npm.taobao.org/
At this point, We introduced how to modify the npm image in Node.js. We hope the above content will be helpful to everyone.
The above is the detailed content of How to modify the image in nodejs. For more information, please follow other related articles on the PHP Chinese website!