What's up, everyone? I'll show you how to set up your NPM to use an HTTP proxy today. A long time ago, I had a problem at a previous job where internet access was proxied and fixed to a specific endpoint.
This article is for you if you had this connection problem or if you want to use a proxy to cache some files.
To put this scenario to the test, we'll use a known caching proxy, Squid with authentication. So, make your favorite coffee ☕, and let's get started on a kernel update.

Squid Proxy
It's time to use Docker to build a squid proxy. To prepare this container, we must configure squid.conf with basic authentication; I chose this method to test a proxy with all features.
Remember to keep all assets in the same directory.
- squid.conf
More information can be found in the official docs.
- passwords
This password was generated using the Apache htpassword tool with the known and strong credentials user foo and password boo 🤣.
- Dockerfile
- docker-compose.yml
It is now time to build our squid proxy, which will listen on port 3128.
The curl
command will be used to test the proxy, with success using credentials and failure without credentials.
NPM
Okay, Squid Proxy is up and running, so let's set up NPM config, with command bellow.
Next, we'll install Surge, an amazing static web publishing platform with a free tier.
As a result, your NPM package should be successfully installed.
Cleanup
If you want to clean up your proxy settings, run the script below.
Finally
If you prefer, you can clone the repository
We built a Squid Proxy to test NPM with HTTP Proxy, but we can test with any tool that supports HTTP Proxy endpoint configuration. I admit that it is difficult to set up an environment when there is an HTTP Proxy, so when things do not work as expected, we must find a workaround.🔨
New packages are built and assembled on your kernel. God bless you. Please leave a comment or share to help me improve my articles. Bye! 🫶