set npm proxy without using http:// before the proxy server name - node.js

I have npm installed and have used it a few times but unfortunately I had to change my proxy and I am not able to get it to work again.
here are my past settings:(the ones that worked)
npm config get proxy: http://proxy-foo.foobar.com:8080
npm config get https-proxy: http://proxy-foo.foobar.com:8080
now my proxy is a server name and when I use the proxy in my browser it works fine, but when I set the config in npm it fails with 'getaddrinfo ENOTFOUND'
current settings:
npm config get proxy: http://servername:8080
npm config get https-proxy: http://servername:8080
in my browsers proxy I do not use http:// before the server name and I think this is what is causing it to fail. could this be the problem and if so is there a way to set proxy configs in npm without using http:// before.

You're right; npm (more accurately, request, which actually does the fetching) does care about the http:// before the proxy name.
The proxy setting should be a fully-qualified URL that you could visit in a browser, e.g.,
http://proxy.company.com:port/
or
http://1.1.1.1:1234/
if specified as an IP address.

Related

npm request failed, reason: connect ETIMEDOUT 104.16.16.35:443

We are trying to get npm to work on a Windows Server 2019.
The server is configured like this:
The server runs as a guest in the ESX VMWare environment.
Server runs behind a checkpoint firewall and a ClearSwift proxy (several antivirus engines active).
An F5 load balancing reverse proxy is run internally in the MSM network via DNS.
Server is running Bitdefender AntiVirus
Server runs with Windows2019 current patch status.
Current firewall settings:
All Denied LAN> Intranet
All Denied Intranet> LAN
We always get this error, no matter what we tried:
This is what we tried so far:
npm config set registry "http://registry.npmjs.org/"
ping proxy
npm config set proxy https-proxy http://proxy.johndoe.corp:8080
npm config set https-proxy http://proxy.johndoe.corp:8080
npm config set strict-ssl false
set HTTPS_PROXY=http://proxy.johndoe.corp:8080
set HTTP_PROXY=http://proxy.johndoe.corp:8080
npm --proxy http://proxy.johndoe.corp:8080 --without-ssl --insecure -g install
npm install --global gulp#3.9.1
We always get the ETIMEDOUT error, and I wasn't able to find the correct solution on the internet.
Any help is appreciated!

npm install module Error: tunneling socket error

I am not able to install nodejs modules using npm on windows. I am behind a proxy and I set the proxy like this:
npm config set proxy internet.cp:8080
npm config set proxy-http internet.cp:8080
When I try to install a packet, i get this error:
npm info retry will retry, error on last attempt: Error: tunneling socket could not be established
I have some questions:
- how can I make npm work with socks5
- can I configure a proxycap file so that npm will use socks5
- other suggestions
It may be happening due to your proxy which is preventing https requests.
Try executing the below command before installing the packets.
npm config set registry http://registry.npmjs.org/
Hope this helps!
It turned out that the proxy I used wasn't the right one. Afeter using the right proxy, and setting it with the commands above, it worked.
npm config set proxy internet.cp:8080
npm config set proxy-http internet.cp:8080

How to setup Node.js behind a corporate proxy

I have installed node.js in my windows machine which is in a corporate network. So i will have to use my Id and password to access internet through the proxy server.
I have read that we can use npm config set proxy to set the proxy.
npm config set proxy http://ABC\\123456:password#proxy.ABC.com:6050
I have tried it and is not working.
How can i specify the proxy details including username and password in NPM??
My user name is domain\username and password has special characters '!' and '#'
First open a command console at the location of your npm installation.
Then you can configure your npm to use a proxy using the commands:
npm config set proxy http://{url}:{port}
npm config set https-proxy http://{url}:{port}
Notice the protocol is set to http for both the proxy and https-proxy variables.
If you would like npm to store your credentials for the proxy,
you can additionally modify the commands as follows:
npm config set proxy http://{username}:{passphrase}#{url}:{port}
npm config set https-proxy http://{username}:{passphrase}#{url}:{port}
For example:
npm config set proxy http://LanguidSquid:Password1#my.company.com:8080
npm config set https-proxy http://LanguidSquid:Password1#my.company.com:8080
Additional information here: Using npm behind corporate proxy .pac
It's simple:
npm config set proxy http://username:password#proxy.company.com:8080
EDIT: Sorry didn't read about special chars:
You have to encode the special characters. E.g. instead of this:
http://username:p#ssword#proxy.company.com:8080
you have to write this:
http://username:p%40ssword#proxy.company.com:8080
Open an command prompt or terminal session and run the following commands to configure npm to work with your web proxy. The commands use proxy.company.com as the address and 8080 as the port.
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

Node.js global proxy setting

I was working in a corporate network behind a proxy server. In my code I can set the proxy by using the approach mentioned in this thread.
But the problem is that most of the 3rd party modules do not have proxy setting and I cannot modify their code to add the proxy. Also, my code might be used in a direct connection environment which means I cannot hard-code my proxy setting in code.
I know NPM has a global setting for proxy which is
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
But I didn't find any config similar in Node.js.
Does Node.js support global proxy setting so that I don't need to change all codes and switch on and off easily?
Unfortunately, it seems that proxy information must be set on each call to http.request. Node does not include a mechanism for global proxy settings.
The global-tunnel-ng module on NPM appears to handle this, however:
var globalTunnel = require('global-tunnel-ng');
globalTunnel.initialize({
host: '10.0.0.10',
port: 8080,
proxyAuth: 'userId:password', // optional authentication
sockets: 50 // optional pool size for each http and https
});
After the global settings are establish with a call to initialize, both http.request and the request library will use the proxy information.
The module can also use the http_proxy environment variable:
process.env.http_proxy = 'http://proxy.example.com:3129';
globalTunnel.initialize();
I finally created a module to get this question (partially) resolved. Basically this module rewrites http.request function, added the proxy setting then fire. Check my blog post: https://web.archive.org/web/20160110023732/http://blog.shaunxu.me:80/archive/2013/09/05/semi-global-proxy-setting-for-node.js.aspx
You can try my package node-global-proxy which work with all node versions and most of http-client (axios, got, superagent, request etc.)
after install by
npm install node-global-proxy --save
a global proxy can start by
const proxy = require("node-global-proxy").default;
proxy.setConfig({
http: "http://localhost:1080",
https: "https://localhost:1080",
});
proxy.start();
/** Proxy working now! */
More information available here: https://github.com/wwwzbwcom/node-global-proxy
While not a Nodejs setting, I suggest you use proxychains which I find rather convenient. It is probably available in your package manager.
After setting the proxy in the config file (/etc/proxychains.conf for me), you can run proxychains npm start or proxychains4 npm start (i.e. proxychains [command_to_proxy_transparently]) and all your requests will be proxied automatically.
Config settings for me:
These are the minimal settings you will have to append
## Exclude all localhost connections (dbs and stuff)
localnet 0.0.0.0/0.0.0.0
## Set the proxy type, ip and port here
http 10.4.20.103 8080
(You can get the ip of the proxy by using nslookup [proxyurl])
replace {userid} and {password} with your id and password in your organization or login to your machine.
npm config set proxy http://{userid}:{password}#proxyip:8080/
npm config set https-proxy http://{userid}:{password}#proxyip:8080/
npm config set http-proxy http://{userid}:{password}#proxyip:8080/
strict-ssl=false

Getting Node.io to work through a proxy

I'm trying to use node.io (web scraping module) through a proxy. I know it has untested support for proxies built in, but I cannot get it to work. Does anyone know how to get it working?
Thanks,
You have to configure npm to make node to use a proxy server;
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080'

Resources