Using Node.JS behind a proxy

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:


Requests from Node

var http = require("http");

var options = {
  host: "proxy",
  port: 8080,
  path: "",
  headers: {
    Host: ""
http.get(options, function(res) {

For HTTPS, Try this:

var http = require('http');

http.get ({
    host: '',
    port: 8888,
    path: ''
}, function (response) {
    console.log (response);

In order to use NPM, try something like this:

  1. I run this command: npm config set strict-ssl false
  2. Then set npm to run with http, instead of https: npm config set registry ""
  3. Then I install packages using this syntax: npm --proxy 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}








One response to “Using Node.JS behind a proxy”

  1. Deepak Avatar

    Wow this works!! Used behind a corporate firewall to install bower using NodeJS and it worked!

    Thanks Luke! :D