While working with NodeJs you’ll notice that many a times you might not be able to install or update while working behind a proxy network like the corporate web proxy of your office etc. Basically you might notice that the commands like npm install is not working. However, this can be easily fixed by setting the proxy of NodeJs using config command. You would have to set the proxy for both http and https proxy.
In NodeJs the npm uses a configuration file which can be easily edited using the
npm config edit command. You can use that to set the proxy values directly into the file. As an alternative you can also use the
npm config set <key> <value> command to set the http-proxy value. Following is the code you would require to set the proxy using the npm config in NodeJs :
npm config set proxy http://your-company-proxy.com:8080
npm config set https-proxy http://your-company-proxy.com:8080
If your network requires a username password then please pass it in like :
npm config set https-proxy http://username:[email protected]:8080
Also remember to you might have to url encode the proxy url if there are special character in it . Especially if you have characters like “@” within your password, you might have to replace it with relevant ASCII code.