Setting up Node.js and npm behind corporate proxies was genuinely painful when I first encountered it. After using Yeoman and Grunt in open networks, I naively assumed npm just worked everywhere. Corporate reality had other plans.
This is my definitive reference for getting npm working behind corporate firewalls, but hopefully useful for others facing the same issues. I was trailing this on Windows, after switching to Apple Mac platform in the longest time. While I wait to get my hands on a Macbook, I pushed on setting it up on this Lenova machine.
Prerequisites
Verify your installations first:
node --version
# Should return something like: v0.10.21
git --version
# Should return: git version 1.8.4.msysgit.0
If git commands fail on Windows, add to your PATH environment variable:
C:\Program Files\nodejs\;C:\Program Files\Git\bin;C:\Program Files\Git\cmd;
Proxy Configuration (Choose One Method)
Method 1: Environment Variables
HTTP_PROXY=http://proxy.company.com:8080
HTTPS_PROXY=https://proxy.company.com:8080
Method 2: NPM Config Commands
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080
Method 3: .npmrc File (Recommended)
Create/edit C:\Users\USERNAME\.npmrc:
strict-ssl=false
registry=http://registry.npmjs.org/
proxy=http://username:password@proxy.company.com:8080
https-proxy=http://username:password@proxy.company.com:8080
\
Git Configuration for Bower
Corporate networks often block git:// protocols. Fix this:
git config --global url."https://".insteadOf git://
Common Issues & Fixes
Grunt command not recognised:
- Check where npm modules are installed:
npm config get prefix - Add that path to your PATH environment variable
Spawn ENOENT error:
- Add
%SystemRoot%\system32;to your PATH environment variable
Module permission issues:
- Verify npm prefix location and ensure you have write access
- Sometimes modules end up on different drives due to corporate restrictions
Quick Verification
Test everything works:
npm install -g grunt-cli
grunt --version
If both commands work without errors, you're sorted.
Personal note: Keep the .npmrc method, it's the most reliable across different corporate setups and survives system restarts. The environment variable approach tends to get wiped by IT policies.
Next: Actually getting that npm-grunt boilerplate finished and shared.