How to fix Error: HTTP 407 Proxy Authentication Required in Node.js

Node.jsINTERMEDIATEMEDIUMUpdated Dec 9, 2025· 195 views

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
  1. Configure npm proxy with authentication
  2. Set proxy environment variables for Node.js applications
  3. Use .npmrc file for project-specific configuration
  4. Configure proxy in your Node.js application code
node.js — error
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080
Error: 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

  1. Proxy credentials (username/password) not configured in npm configuration or environment variables
  2. Incorrect username or password stored in .npmrc or system credentials
  3. Special characters in password not properly URL-encoded in proxy configuration
  4. Proxy authentication method (NTLM, Kerberos) not supported by Node.js or npm natively
  5. Cached or outdated credentials stored in Windows Credential Manager or system keychain
  6. HTTP_PROXY and HTTPS_PROXY environment variables not set or missing credentials
  7. Corporate proxy settings changed (new password, different proxy server)
  8. Node.js application not configured to use system proxy settings
  9. Proxy server requires additional authentication headers beyond basic credentials

How to fix "Error: HTTP 407 Proxy Authentication Required"

1Configure npm proxy with authentication

Set your proxy configuration with credentials directly in npm:

bash
npm config set proxy http://username:password@proxy.company.com:8080
npm config set https-proxy http://username:password@proxy.company.com:8080

If your password contains special characters (@, !, $, #, etc.), URL-encode them:
- @ becomes %40
- ! becomes %21
- # becomes %23
- $ becomes %24

Example with special characters:

bash
npm config set proxy http://john%40doe:P%40ssw0rd%21@proxy.company.com:8080

You can also use an online URL encoder or Node.js:

javascript
const encoded = encodeURIComponent('P@ssw0rd!');
console.log(encoded); // P%40ssw0rd%21
2Set proxy environment variables for Node.js applications

Configure environment variables that Node.js and many libraries respect:

Linux/macOS (bash/zsh):

bash
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=1

Add these to ~/.bashrc or ~/.zshrc for persistence.

Windows (Command Prompt):

cmd
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=1

Windows (PowerShell):

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().

3Use .npmrc file for project-specific configuration

Create a .npmrc file in your project root or home directory:

ini
proxy=http://username:password@proxy.company.com:8080
https-proxy=http://username:password@proxy.company.com:8080
strict-ssl=true

For security, avoid committing credentials to version control. Use environment variables instead:

bash
.npmrc
proxy=http://${PROXY_USER}:${PROXY_PASS}@proxy.company.com:8080
https-proxy=http://${PROXY_USER}:${PROXY_PASS}@proxy.company.com:8080

Then set environment variables:

bash
export PROXY_USER=your-username
export PROXY_PASS=your-password
4Configure proxy in your Node.js application code

For applications making HTTP requests, configure the proxy programmatically:

Using native fetch() (Node.js 18+):

javascript
// 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:

bash
npm install proxy-agent
javascript
import { 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:

bash
npm install axios
javascript
import 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'
    }
  }
});
5Clear cached credentials and verify configuration

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:

bash
npm config get proxy
npm config get https-proxy

Test the configuration:

bash
npm ping
# or
npm install express --verbose

The --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:

bash
# Configure CNTLM with your credentials
   cntlm -H -u username -d DOMAIN
   # Then point npm to localhost
   npm config set proxy http://localhost:3128

2. Px Proxy: A Python-based alternative (https://github.com/genotrance/px):

bash
pip install px-proxy
   px --proxy=proxy.company.com:8080
   npm config set proxy http://localhost:3128

Security Considerations:
- Never commit proxy credentials to version control
- Use environment variables or secure credential storage
- Consider using a .env file with dotenv library:

javascript
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:

bash
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:

bash
npm install pac-proxy-agent
javascript
import { 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