Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

http.get through vpn + node

http.get through vpn + node


I want to be able to do a Http.get request through node within my own vpn, but it seems likes the Function is passing the website to a dns instead of look in my vpn. This following code works with google as the host.

http = require('http');
var host = "";
var options = {host:host, port:80, path:'/'}

http.get( options, function( res ){
    res.on( 'data', function( chunk ){
          console.log( chunk );

but when I change host to it throws a Domain name not found error, but when i type on firefox I am able to load the page. I guess one way I can fix this is to find out the host name's ip but is there an easier way? :D

I resolve my own answer, but to answer the question in the follow up, the answer is yes here is a snippet that shows that, by doing an DNS ip lookup then going to google by IP.

var dns = require('dns');
var http = require('http');

dns.resolve4('', function (err, addresses) {
    if (err) throw err;

    console.log('addresses: ' + JSON.stringify(addresses));

    var options = {
    host: addresses[0]

    http.get(options, function(res){
      console.log("Sending http request to google with options", options);
      var htmlsize = 0;
      res.on('data', function( chunk ){
      res.on('end', function(){
          console.log( "got html of lenght", htmlsize );

And this is the output

addresses: ["","","","",""]
Sending http request to google with options { host: '' }
got html of lenght 33431
Problem courtesy of: Doboy


http does resolve addresses correctly that are in a VPN, but I just had a small typo.

Solution courtesy of: Doboy


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

http.get through vpn + node


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription