I have my Raspberry Pi setup at work and it is stuck behind a proxy. Here are some helpful tips I have found from across the web:
var http = require("http"); var options = { host: "proxy", port: 8080, path: "http://www.google.com", headers: { Host: "www.google.com" } }; http.get(options, function(res) { console.log(res); res.pipe(process.stdout); }); For HTTPS, Try this:
var http = require('http'); http.get ({ host: '127.0.0.1', port: 8888, path: 'https://www.google.com/accounts/OAuthGetRequestToken' }, function (response) { console.log (response); });
In order to use NPM, try something like this:
- I run this command:
npm config set strict-ssl false
- Then set npm to run with http, instead of https:
npm config set registry "http://registry.npmjs.org/"
- Then I install packages using this syntax:
npm --proxy http://username:password@cacheaddress.com.br:80 install packagename
Skip the username:password
part if proxy doesn’t require you to authenticate
or this:
npm config set proxy http://proxy_host:port
or this:
npm --proxy http://proxy-server:8080/ install {package-name}
Comments
One response to “Using Node.JS behind a proxy”
Wow this works!! Used behind a corporate firewall to install bower using NodeJS and it worked!
Thanks Luke! :D