I am having trouble running npm install over a socks5 proxy.
Proxy is running locally, to tunnel http(s) over ssh to company intranet: ssh -vvv -D 5000 -N <SERVER_IP>
I have configured npm's proxy:
npm config set proxy socks5h://localhost:5000
npm config set https-proxy=socks5h://localhost:5000
I just get:
npm ERR! git clone https://<INTRANET>/repo fatal: unable to access 'https://<INTRANET>/repo/': Could not resolve host: <INTRANET>
Any ideas?
P.S.: git clone from the same git repo address works perfectly.
Ok, as of now, npm does not support socks proxy: https://github.com/npm/npm/issues/6204
I now use ProxyCap.
http://www.proxycap.com
Works great. It will manage the ssh tunnel + socks proxy and route all traffic automatically (also for npm) through it.
Proxifier works for me. Simply add a proxy and npm install ...
.com/mac/
You can use polipo to convert sock5 proxy to http proxy, and it's super convenient if you're under Linux.
You can reference this page for further detail:
Convert Socks Proxy To Http Proxy: Using Polipo
For a workaround that works on both Linux and Windows, you can use http-proxy-to-socks.
$ npm install -g http-proxy-to-socks
$ hpts -s 127.0.0.1:1080 -p 8080
Now you have you http proxy at port 8080.
Use v2rayN as client.
It will launch both socks5 and http proxy.
Then you can use its http proxy for npm proxy and socks5 for other proxy at same time.
// http for npm
npm config set http-proxy http://127.0.0.1:10809
// socks5 for git
git config --global http.proxy 'socks5://127.0.0.1:10808
v2raN UI Screen Shot
Related
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!
I am looking to create a locally running Node.js server that can intercept outgoing requests to the NPM registry (npmjs.org, or whatever).
Is that what a reverse proxy is?
Basically what I would like to do is create a locally running NPM registry - this is for use with locally running Docker containers. Normally I would just use npm link for local development. But when testing libraries using Docker locally, using npm link for that becomes hard to impossible
I know there are some libraries out there that set up a local NPM registry, but I am looking to do this from scratch so I can set it up for my use case. Essentially I want to tarball packages that exist on my filesystem each time an npm install request comes in.
I started experimenting with:
npm config set registry http://localhost:3440
but when I subsequently did an npm install, it didn't seem to hit my locally running server, just went to registry.npmjs.org like normal.
I also tried modifying /etc/hosts
before:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
after:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
registry.npmjs.org localhost:3440
but my local server listening on port 3440 did not seem to intercept any traffic.
That's not a reverse proxy, but that's a forward proxy. And you'll effectively have to use npm config set proxy to use it from npm call.
The main tool used for such proxy is usually squid proxy. And I'm pretty sure you can build more robust and feature-full service using some well known forward proxy tools instead of a custom nodejs tool.
Then you'll have to check where this service is running (on the same docker? on another docker? on your host?). The address you set for npm, in npm config set proxy must be resolvable from inside the container running npm (but it may differ between commands running on the Dockerfile step and commands running in a bash session after that build).
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
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
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