How can I configure npm to work with a corporate proxy?

I’m having trouble getting npm install to work on my company network. We use a proxy server and I can’t seem to figure out how to make npm play nice with it. I’ve already tried updating the proxy settings in my .npmrc file but that didn’t solve the issue.

Does anyone know a reliable way to set this up? I’d really like to avoid having to manually download packages every time. It’s becoming a real pain and slowing down my workflow.

I’ve seen some suggestions online about using environment variables or command line flags, but I’m not sure which approach is best or how to implement them correctly. Any tips or step-by-step instructions would be super helpful!

// Example of what I've tried in .npmrc
proxy=http://proxy.company.com:8080
https-proxy=http://proxy.company.com:8080

Thanks in advance for any help you can provide!

I’ve been there, dealing with corporate proxies can be a real headache. What worked for me was using both the .npmrc file and environment variables. Here’s what I did:

First, I set up my .npmrc file like you did, but I also added the ‘strict-ssl=false’ line:

proxy=http://proxy.company.com:8080
https-proxy=http://proxy.company.com:8080
strict-ssl=false

Then, I set these environment variables in my terminal:

export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080

If you’re on Windows, use ‘set’ instead of ‘export’.

After that, npm started working like a charm. Don’t forget to replace ‘proxy.company.com:8080’ with your actual proxy details.

One more thing - if you’re still having issues, try running ‘npm config list’ to see all your current settings. Sometimes there are conflicting configurations that aren’t immediately obvious.

Hope this helps! Let me know if you need any more details.

hey man, have u tried using a npm mirror? some companies set up internal mirrors to avoid proxy hassles. ask ur IT if they got one. if not, try npm config set registry https://registry.npmjs.org/ and see if that helps. also check if ur proxy needs authentication. if it does, u gotta add those creds to ur .npmrc file too

Having worked in corporate environments, I can attest that proxy issues with npm are common. One approach that’s often overlooked is using a local npm cache. You can set this up by running ‘npm config set cache C:\path\to\npm-cache’ (adjust the path as needed). This can help reduce network requests and bypass some proxy-related problems.

Another useful trick is to configure npm to use HTTPS instead of HTTP for Git dependencies. Add ‘git-https-instead-of-git=true’ to your .npmrc file. This can sometimes resolve issues where the proxy is blocking Git protocol.

If all else fails, consider talking to your IT department. They might have specific instructions for your company’s network setup or could potentially whitelist npm’s domains on the proxy server. Remember, you’re likely not the first developer to face this issue in your organization.