Setup Node.js and Npm 'Proxy' config if you are behind a proxy


Are you getting below error while using the npm?

"Error: connect ECONNREFUSED" and "If you are behind a proxy, please make sure that the
'proxy' config is set properly.  See: 'npm help config'".  As shown in below image


Node.js proxy Error

If you get above error, then you are proxy might not set properly for npm.

To Set the proxy for the Node.js, use below syntax
npm config set proxy "http://<PROXY_SERVER>:<PORT>"

We can also Pass username and password, If Proxy needs it like below
npm config set proxy http://username:password@<PROXY_SERVER>:<PORT>

In some cases, we might be using special characters for our passwords(like @ in password), in this case above syntax wont work. So its better to use double quotes (") for username:password as shown below.
npm config set proxy http://"username:password"@<PROXY_SERVER>:<PORT>

We can also use below to set https_proxy
npm config set https-proxy http://<PROXY_SERVER>:<PORT>
 

No comments:

Post a Comment