How to fix Error: HTTP 407 Proxy Authentication Required in Node.js
This error occurs when your Node.js application or npm tries to connect through a proxy server that requires authentication credentials. The request is rejected because no valid username and password were provided to the proxy.
Quick fix
Fixes 407
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080- Configure npm proxy with authentication
- Set proxy environment variables for Node.js applications
- Use .npmrc file for project-specific configuration
- Configure proxy in your Node.js application code
npm config set proxy http://username:password@proxy.company.com:8080npm config set https-proxy http://username:password@proxy.company.com:8080Error: HTTP 407 Proxy Authentication Required
What this error means
The HTTP 407 Proxy Authentication Required error indicates that your Node.js application is attempting to make an HTTP/HTTPS request through a corporate or network proxy server, but the proxy requires authentication credentials that weren't provided or were invalid. Unlike a 401 Unauthorized error (which comes from the destination server), a 407 response comes from the intermediate proxy server itself. The proxy sits between your application and the internet, and it won't forward your request until you prove you're authorized to use it. This is extremely common in corporate environments where all internet traffic must pass through authenticated proxy servers for security, monitoring, or policy enforcement purposes. The proxy server sends back a 407 status code along with a Proxy-Authenticate header that specifies which authentication methods it supports (Basic, Digest, NTLM, or custom schemes).
Typical symptoms
- npm install fails with "407 Proxy Authentication Required" or "EPROXYAUTH" error
- HTTP requests in Node.js applications timeout or fail with 407 status code
- Package managers (npm, yarn, pnpm) cannot download dependencies
- Node.js fetch() or http.request() calls fail when accessing external URLs
- Error occurs only in corporate network environments, works fine at home or on mobile hotspot
- Git operations fail with proxy authentication errors
- Docker pulls and other tools fail with similar proxy authentication issues
Common causes
- Proxy credentials (username/password) not configured in npm configuration or environment variables
- Incorrect username or password stored in .npmrc or system credentials
- Special characters in password not properly URL-encoded in proxy configuration
- Proxy authentication method (NTLM, Kerberos) not supported by Node.js or npm natively
- Cached or outdated credentials stored in Windows Credential Manager or system keychain
- HTTP_PROXY and HTTPS_PROXY environment variables not set or missing credentials
- Corporate proxy settings changed (new password, different proxy server)
- Node.js application not configured to use system proxy settings
- Proxy server requires additional authentication headers beyond basic credentials
How to fix "Error: HTTP 407 Proxy Authentication Required"
Set your proxy configuration with credentials directly in npm:
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080If your password contains special characters (@, !, $, #, etc.), URL-encode them:
- @ becomes %40
- ! becomes %21
- # becomes %23
- $ becomes %24
Example with special characters:
npm config set proxy http://john%40doe:P%40ssw0rd%21@proxy.company.com:8080You can also use an online URL encoder or Node.js:
const encoded = encodeURIComponent('P@ssw0rd!');
console.log(encoded); // P%40ssw0rd%21Configure environment variables that Node.js and many libraries respect:
Linux/macOS (bash/zsh):
export HTTP_PROXY=http://username:password@proxy.company.com:8080
export HTTPS_PROXY=http://username:password@proxy.company.com:8080
export NO_PROXY=localhost,127.0.0.1,.company.com
export NODE_USE_ENV_PROXY=1Add these to ~/.bashrc or ~/.zshrc for persistence.
Windows (Command Prompt):
set HTTP_PROXY=http://username:password@proxy.company.com:8080
set HTTPS_PROXY=http://username:password@proxy.company.com:8080
set NO_PROXY=localhost,127.0.0.1
set NODE_USE_ENV_PROXY=1Windows (PowerShell):
$env:HTTP_PROXY="http://username:password@proxy.company.com:8080"
$env:HTTPS_PROXY="http://username:password@proxy.company.com:8080"
$env:NO_PROXY="localhost,127.0.0.1"
$env:NODE_USE_ENV_PROXY="1"The NODE_USE_ENV_PROXY flag (Node.js v22.21.0+) enables native proxy support for http, https, and fetch().
Create a .npmrc file in your project root or home directory:
proxy=http://username:password@proxy.company.com:8080
https-proxy=http://username:password@proxy.company.com:8080
strict-ssl=trueFor security, avoid committing credentials to version control. Use environment variables instead:
.npmrc
proxy=http://${PROXY_USER}:${PROXY_PASS}@proxy.company.com:8080
https-proxy=http://${PROXY_USER}:${PROXY_PASS}@proxy.company.com:8080Then set environment variables:
export PROXY_USER=your-username
export PROXY_PASS=your-passwordFor applications making HTTP requests, configure the proxy programmatically:
Using native fetch() (Node.js 18+):
// Enable environment proxy support
process.env.NODE_USE_ENV_PROXY = '1';
// fetch() will automatically use HTTP_PROXY/HTTPS_PROXY
const response = await fetch('https://api.example.com/data');Using https.request() with proxy-agent:
npm install proxy-agentimport { ProxyAgent } from 'proxy-agent';
const agent = new ProxyAgent({
getProxyForUrl: () => 'http://username:password@proxy.company.com:8080'
});
const options = {
hostname: 'api.example.com',
path: '/data',
agent: agent
};
https.request(options, (res) => {
// Handle response
});Using axios:
npm install axiosimport axios from 'axios';
const response = await axios.get('https://api.example.com/data', {
proxy: {
protocol: 'http',
host: 'proxy.company.com',
port: 8080,
auth: {
username: 'your-username',
password: 'your-password'
}
}
});Old or incorrect credentials can cause persistent 407 errors even after updating configuration.
Windows - Clear Credential Manager:
1. Open Control Panel → Credential Manager
2. Look under "Windows Credentials" and "Generic Credentials"
3. Remove any entries related to your proxy server
4. Restart your terminal and try again
macOS - Clear Keychain:
1. Open Keychain Access app
2. Search for your proxy server name
3. Delete any related entries
4. Restart your terminal
Verify npm configuration:
npm config get proxy
npm config get https-proxyTest the configuration:
npm ping
# or
npm install express --verboseThe --verbose flag shows exactly what npm is doing and where it fails.
Advanced notes
NTLM/Kerberos Authentication:
Corporate proxies often use NTLM (Windows-integrated) or Kerberos authentication, which npm and Node.js don't support natively. Solutions include:
1. CNTLM Proxy: Install CNTLM (http://cntlm.sourceforge.net/), a local authentication proxy that handles NTLM:
# Configure CNTLM with your credentials
cntlm -H -u username -d DOMAIN
# Then point npm to localhost
npm config set proxy http://localhost:31282. Px Proxy: A Python-based alternative (https://github.com/genotrance/px):
pip install px-proxy
px --proxy=proxy.company.com:8080
npm config set proxy http://localhost:3128Security Considerations:
- Never commit proxy credentials to version control
- Use environment variables or secure credential storage
- Consider using a .env file with dotenv library:
import 'dotenv/config';
const proxyUrl = `http://${process.env.PROXY_USER}:${process.env.PROXY_PASS}@proxy.company.com:8080`;- Add .env and .npmrc to .gitignore
Self-Signed Certificates:
If your proxy uses a self-signed certificate, you may need:
npm config set strict-ssl false
# or
export NODE_TLS_REJECT_UNAUTHORIZED=0⚠️ Warning: Disabling SSL verification reduces security. Only use in trusted corporate environments.
Proxy Auto-Configuration (PAC) Files:
Some organizations use PAC files for dynamic proxy configuration. Node.js doesn't support PAC files natively. Use the pac-proxy-agent package:
npm install pac-proxy-agentimport { PacProxyAgent } from 'pac-proxy-agent';
const agent = new PacProxyAgent('http://proxy.company.com/proxy.pac');Troubleshooting Tips:
- Check if your proxy requires domain\username format: DOMAIN\username or username@domain.com
- Some proxies log authentication failures - contact your IT team with timestamps
- Test proxy connectivity outside Node.js: curl -x http://username:password@proxy.company.com:8080 https://registry.npmjs.org
- Use --loglevel verbose or --loglevel silly with npm commands for detailed debugging
Frequently asked questions
- What does "407" mean?
- js application is attempting to make an HTTP/HTTPS request through a corporate or network proxy server, but the proxy requires authentication credentials that weren't provided or were invalid. Unlike a 401 Unauthorized error (which comes from the destination server), a 407 response comes from the intermediate proxy server itself. The proxy sits between your application and the internet, and it won't forward your request until you prove you're authorized to use it.
- How do I fix "407"?
- This error occurs when your Node.js application or npm tries to connect through a proxy server that requires authentication credentials. The request is rejected because no valid username and password were provided to the proxy.
- What causes "407"?
- Proxy credentials (username/password) not configured in npm configuration or environment variables Incorrect username or password stored in .npmrc or system credentials Special characters in password not properly URL-encoded in proxy configuration
- Is the "407" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Node.js Official Documentation
- 📖Node.js HTTP Documentation(Official Docs)
- 📖MDN: 407 Proxy Authentication Required(Official Docs)
- 🐙
- 📝