NodeJs API msrestazure proxy issue - node.js

I've a nodejs api that uses npm package msrestazure.
From my local development I've to pass via enterprise proxy to get to the internet.
When I try msRestAzure.loginWithServicePrincipalSecret I get a connection timeout due to the fact that request doesn't use the proxy.
Error: connect ETIMEDOUT 52.143.136.20:443
If someone knows how I can force the usage of the proxy tell me.
For info i've tested multiple solution
set proxy environment variable : not running
use netsh winhttp to set proxy : not running
use software proxycap : it runs. But software is not free and can't request to other developper to use it.
Any has an idea ?? Issue is only for request done by the package.
If i use http request to do the request my self, it works :(
Thanks for your help

sorry for delay ...
Solution is to use package npm dotenv and add HTTP_PROXY and HTTPS_PROXY variable in it.
Hope that can help :)

Related

Access watson retrieve and rank behind a proxy in Node

I need to know if the R&R service can be used behind a proxy.
Take a look at the next part to see my investigations.
The code I'm using was working at my home. (No firewall/No Proxy, only a router)
I started from the following code.
https://console.eu-gb.bluemix.net/catalog/starters/personality-insights-nodejs-web-starter
I try to execute it locally and it was working using the following configuration to be able to install the modules.
npm config set registry http://registry.npmjs.org
npm config set proxy http://x.x.x.x:xx
npm config set https-proxy http://x.x.x.x:xx
npm config set strict-ssl false
set http_proxy=http://x.x.x.x:xx
set https_proxy=http://x.x.x.x:xx
set HTTP_PROXY=http://x.x.x.x:xx
set HTTPS_PROXY=http://x.x.x.x:xx
As it was working I started playing around with R&R. But I'm only having an error.
Error searching for documents: Error: connect ETIMEDOUT 158.85.132.88:443
Where the ip address corresponds gateway.watsonplatform.net
ping gateway.watsonplatform.net
PING gateway.watsonplatform.net (158.85.132.88) 56(84) bytes of data.
Because of the firewall the ping are blocked
During my investigations I found that when executing my test for the R&R service every time two ICMP request are send.
Probably because of the firewall. But why this service would need to send ICMP packets ?
Just to recap:
The code is working when there is no firewall/no proxy
The personnality Insight service is working behind proxy/firewall
The R&R isn't
EDIT
After some investigations I've found that there was a bug in the Solr-client so it is currently impossible to make it work.
More info here on this github issue.

Installing Express in Node.js

I am getting error while installing Express to use in Node.js
I have attached screenshot of the command prompt.
I am not getting what this error is. Please let me know what this error say, so that I can fix it.
Possible problems:
no internet connection
DNS resolver misconfigured
proxy settings required
You can try the following commands to narrow down the problem:
host registry.npmjs.org
ping registry.npmjs.org
curl http://registry.npmjs.org/
curl https://registry.npmjs.org/

Error: Invalid protocol

I am facing this issue while making a request to any url using NodeJS.
FYR i have made a script in nodejs which is using request module that calls a page and then scrap that html page but the issue is when it calls i gets an error "Error: Invalid protocol: 10.112.62.78".
My .npmrc file contains following lines
proxy=http://10.112.62.78:8080
https-proxy=http://10.112.62.78:8080
registry=http://registry.npmjs.org/
and i still get following error
[Error: Invalid protocol: 10.112.62.78:]
I have tried all possible combinations of following
http://user:password#proxy:port
http://"user:password"#proxy:port
For the above two i get "URI Malformed error"
Still no solution
http://proxy.company.com:port
FYI Versions are as follows:
>node -v
>v0.12.0
>npm -v
>2.5.1
There is one more info i have static ip of 10.112.111.86 in IPv4 and ip of 10.112.62.78 with 8080 in Proxy Setting of Browser . Also i am using Windows 7 desktop and i tried with Proxy IP of 10.112.62.78 & without it but no solution however i can't change the IPv4 otherwise my internet connection would be gone.
Please provide some solution i am stuck.
PS: Also tried by changing http To https for https-proxy .
Npmrc is used by npm, not (afaik) requests within your node code, so this is probably a red herring. What code are you using to make the request?

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