node.js – npm behind corporate proxy

If you have trouble running npm behind a corporate proxy which uses a domain, username, password combination, then you can do the following steps to fix it.

Corporate Proxy Rules

User: <Domain name>\<user id>

Password: <Password>

Proxy-ip: ip address or domain name of proxy server

Proxy-port: Port of the proxy ip.

Pre-requisite:

Node.js should be installed.

Steps:

Open Command prompt (WIndows PC)/ Terminal (Mac)

type in the following command

npm config set proxy=http://<Domain name>%5C<user id>:<Password>@<Proxy-ip>:<Proxy port>

npm config set https-proxy=http://<Domain name>%5C<user id>:<password>@<proxy-ip>:<proxy port>

Important steps: Open .npmrc file and validate the settings. Sometime npm will update your password with escape characters. If you see any discrepancy, go ahead and make changes directly in the file.

The file is located under

for windows: c:\Users\<user id>\.npmrc

for mac

type cd ~

This will be user directory.

Word of caution:

npm does not like special characters in the password like ‘-‘, ‘#’, ‘$’ etc. ┬áIf your corporate policy mandates you to have special characters in password, then safely choose ‘@’