NPM Proxy / Registry Configuration

When working with npm (Node Package Manager), you might need to configure a proxy if you are behind a corporate firewall or if you’re accessing the internet through a proxy server. Here’s how you can configure npm to use a proxy, such as http or https, socks5,.etc, Also, you can set a custom or private local registry for npm.

Setting up a proxy for npm:

  1. View Current Configurations:
    To check your current npm configuration, you can use the following command:
    npm config list
  2. Set Proxy:
    You can set the proxy using the npm config set command. Replace the placeholders with your proxy information.
    npm config set proxy http://your-proxy-server:proxy-port
    npm config set https-proxy http://your-proxy-server:proxy-port
  3. Username and Password for Proxy:
    If your proxy requires a username and password, you can set them using the following commands:
    npm config set proxy http://username:password@your-proxy-server:proxy-port
    npm config set https-proxy http://username:password@your-proxy-server:proxy-port
  4. Clear Proxy Configuration:
    If you want to remove the proxy configuration, you can use the npm config delete command:
    npm config delete proxy
    npm config delete https-proxy


npm config set proxy
npm config set https-proxy

Configuration via Environment Variables:

You can also set the proxy configuration using environment variables:

export HTTP_PROXY=http://your-proxy-server:proxy-port
export HTTPS_PROXY=http://your-proxy-server:proxy-port

Verify Configuration:

You can verify your npm configuration by running:

npm config list

Ensure that the proxy settings are correctly displayed in the output.

Remember to replace placeholders like your-proxy-server, proxy-port, username, and password with your actual proxy details.

Note: If you’re behind a firewall, you might also need to configure npm to use the appropriate registry. You can set it using:

npm config set registry

Adjust the registry URL based on your requirements.

Always be cautious when providing sensitive information like usernames and passwords, especially in command-line arguments, as they may be stored in your command history. Consider using environment variables or a more secure method for handling credentials in production scenarios.

Leave a Reply

Your email address will not be published. Required fields are marked *