Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:25:08+00:00 2026-05-30T17:25:08+00:00

I have a little Node.js application that I’d like to hit a remote API

  • 0

I have a little Node.js application that I’d like to hit a remote API to get some date (i.e twitter, microsoft’s translation service, weather). From the docs for Node’s http I tried putting the sample code in my node server app:

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/index.html'
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});

I’ve tried it with the google URL from the docs, a twitter API URL and several others, however the only response I can get is:

Got error: connect ECONNREFUSED

Using the same url with wget gives satisfaction, so I know the URL is valid. What do I need to change to get a successful connection from my app server to a remote service?

OR

Some help on how I can debug this would be even better. Then only information I can seem to get from the failure is ECONNREFUSED. I tried using socket.io to forward the error response to the browser (inside .on('error', function(e){...}) so I could inspect it with webkit. Unfortunately the error object only contains:

Object
    error: Object
        code: "ECONNREFUSED"
        errno: "ECONNREFUSED"
        syscall: "connect"
    __proto__: Object
__proto__: Object

Not really helpful for determining what went wrong.


For reference my entire app.js is:

var express = require('express') , http = require('http') , routes = require('./routes');

var app = module.exports = express.createServer();
var io = require('socket.io').listen(app)

app.configure(function(){
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
  app.use(express.errorHandler());
});

app.get('/', function(req, res){
  routes.index(req, res);
  console.log(req.query);

  var options = {
    host: 'www.google.com',
    port: 80,
    path: '/index.html'
  };

  http.get(options, function(res) {
    console.log("Got response: " + res.statusCode);
  }).on('error', function(e) {
    console.log("Got error: " + e.message);
  });
});

app.listen(4000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:25:10+00:00Added an answer on May 30, 2026 at 5:25 pm

    Me: “Did you make sure that’re sending the request through the proxy that’s setup for your internet connection?”

    me: “no”

    Me: “do that”

    me: “OK, now it works”

      var options = {
        host: '<proxyip>',
        port: <proxyport>,
        path: 'http://www.google.com/index.html'
      };
    
      http.get(options, function(res) {
        console.log("Got response: " + res.statusCode);
      }).on('error', function(e) {
        console.log("Got error: " + e.message);
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little escript file that connects to a node and does some
With more than a little help from daviderossi.blogspot.com I have managed to get some
We have a node.js app that uses node_msyql , a great little library for
I have little doubt about string reading in C. string reading functions like gets,
I have a MainMenu in my app and I would like to have little
I have an application where I want to use node.js and now.js to share
I'm experimenting with a treeview in a little C#/Winforms application. I have programatically assigned
I'm a little new to drupal but have been using things like devel module
Is there a way to install node.js in IIS7? I have very little experience
I have a Drupal view that lists a node called publication. At the top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.