How to set npm config set proxy on npm start - node.js

Hi I'm trying to set a proxy every time I run a specific project with my npm run dev command.
I have something like https://www.npmjs.com/package/dotenv setting up my environment variables but I'm also looking to automating setting my
npm config set proxy http://proxy.example.com:1337
npm config set https-proxy https://proxy.example.com:1337
Does anyone have any solutions for this?
Note That I only want this for my development and note production.

For setting proxy and other configuration for npm just type the following command in the console
npm config edit
this command will open the .npmrc file, in that file set the proxy and other setting related npm
hope it will works.

npm config set proxy http://proxy.example.com:1337 will set the proxy for downloading the packages from npm repo.
when you run npm run dev, what is running is your app which is invoked by npm on node.js on your OS, so you need to set a proxy for your app or your OS.
System level proxy
Linux
https://askubuntu.com/questions/583797/how-to-set-a-proxy-for-terminal
Windows:
set http_proxy=socks5://127.0.0.1:1080
set https_proxy=socks5://127.0.0.1:1080
set ftp_proxy=socks5://127.0.0.1:1080
// unset
set http_proxy=
set https_proxy=
set ftp_proxy=
App level
I can't do anything about that.
Webpack dev server
I believe this is what you need, if you are using webpack dev server.
https://github.com/webpack/webpack-dev-server/blob/master/examples/general/proxy-simple/webpack.config.js

Related

NPM - how to avoid setting npm config every time you open bash

I have set up the proxy in npm with these two commands:
>npm config set https-proxy http://proxy.[Company Name].com:8080
>npm config set https-proxy http://proxy.[Company Name].com:8080
And that worked fine for the time I had bash opened.
But, when I closed bash, and opened it again, I had to do the same thing one more time, since npm config didn't have the proxy set.
How can I set the npm config so that it stays set even after the bash is closed?
You can set npm configurations in user config file ~/.npmrc like below.
proxy=http://user:passsword#host.domain.com:8080/
https-proxy=http://user:passsword#host.domain.com:8080/
strict-ssl=false
registry=http://registry.npmjs.org/
OR you can set the above configurations globally in the below path.
$PREFIX/etc/npmrc
Source

Angular CLI fails on downloading Angular 6 dependencies thru proxy behind

I've successfully installed Angular CLI using NPM behind proxy with Fiddler.
But now I'm facing problem when using 'ng new' command of Angular CLI.
It Always fails to download some dependencies that gives me E502 error.
here is the configuration I used for NPM:
npm config set proxy=http://myproxyserveraddress:8888/
npm config set https-proxy=http://username:password#myproxyserveraddress:8888/
npm config set strict-ssl=false
npm config set registry=https://registry.npmjs.org/
for fiddler, I put check on the Auto Authenticate on the Rules menu.
I also tried the other NPM configurations that was posted here but no luck and those instructions looks outdated now.
Is there an updated configuration setting for creating new project in Angular CLI thru proxy behind?
npm config set proxy http://username:password#myproxyserveraddress:8888/
I think you need set the usn and password in both http and http. And, the character between "proxy" and "http" is a "space" not "=" . Or you can check the username. Ex: my usn in company is xxxx\xxxxxx

npm windows installation proxy issue

I am using below commands to setup proxy on window7
npm config set proxy http://<username>:<password>#<proxy-server-url>:<port>
npm config set https-proxy http://<username>:<password>#<proxy-server-url>:<port>
but I am not able to setup proxy correctly and when I am trying to run the command
npm config get proxy
I am getting erroneous proxy URL as below
http://<username>/:<password>#<proxy-server-url>:<port>
and
it seems slash before colon between "username:password" is getting added incorrectly as "username/:password".
How do I correctly configure npm proxy on windows?
write command in cmd(admin):
this work for me in w10
npm config set https-proxy http://username:password#proxy:port

Jenkins npm/gulp proxy setup

My client project is build via gulp & I would like to configure ci with Jenkins. I have a batch file to execute
npm install
gulp build
I am behind a authenticating proxy, Jenkins do not pickup proxy details even though I have setup
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
& even setup HTTP_PROXY env variable on my Jenkins.
I there a Jenkins plugin for gulp?
The root cause was that Jenkins was running as a different user. When I change the Logon details of the Jenkins process to a user where PROXY details are setup, everything works fine.

phantomjs npm install fails behind proxy

Trying to install PhantomJS via an npm wrapper while behind the corporate proxy. I had already set the http_proxy and https_proxy environment variables so that npm itself would be able to communicate with the registry:
export http_proxy=my-company-proxy.com:80
export https_proxy=my-company-proxy.com:80
But when it came to the node install.js stage of phantomjs, I got a Protocol not supported error:
http.js:1711
throw new Error('Protocol:' + options.protocol + ' not supported.');
^
Error: Protocol:my-company-proxy.com: not supported.
The problem was that the phantomjs npm wrapper code assumes that the proxy info is a complete url, not just a hostname. This resolves the issue:
export http_proxy=http://my-company-proxy.com:80
export https_proxy=http://my-company-proxy.com:80
npm, git, etc work fine with either format, but for this particular package it needs HTTP_PROXY to have a full URL.
UPDATE: this related issue has been resolved and now it can use the same configuration system as npm itself (e.g. if you used npm config command) rather than relying on environment variable.
This is what worked for me.
Open the terminal as an administrator
Navigate to your project folder and enter the following commands
sudo npm config set proxy http://proxy_host:port -g then
sudo npm config set https-proxy http://proxy_host:port -g
Hope this works for you. Good luck.

Resources