The HTTP 502 Bad Gateway error occurs when an intermediate server (like a CDN or proxy) receives an invalid response from the npm registry. This is typically a temporary infrastructure issue.
HTTP 502 indicates that a gateway or proxy server received an invalid response from an upstream server. In npm's case, this usually means the CDN or load balancer couldn't get a proper response from the actual registry servers. This is almost always a temporary infrastructure issue and not something you can fix directly. It often affects only certain geographic regions or CDN edge locations.
Look for known issues:
curl -s https://status.npmjs.org/api/v2/status.json | jq
# Or visit
open https://status.npmjs.org502 errors are often transient:
# Simple retry
npm install
# With delay
for i in 1 2 3; do npm install && break || sleep 30; doneChange DNS resolution path:
# Use different DNS
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Or use VPN to change geographic routingTemporarily switch registry:
npm install --registry https://registry.npmmirror.comThis bypasses the main npm CDN.
Identify where the issue is:
# Trace the route
traceroute registry.npmjs.org
# Test direct connection
curl -v https://registry.npmjs.org/lodashWork offline if possible:
# If packages are in cache
npm install --prefer-offline
# Or use local proxy with cached packagesnpm uses Fastly CDN which has global edge locations. 502 errors often indicate issues at specific edge nodes. Using a VPN to appear from a different region can sometimes route around problem nodes. For production systems, maintain a warm package cache and consider using a caching proxy. Monitor npm status via their API for automated alerting.
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm