Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics (2014) Building a Command Line Application Making a GET Request with http

Chris Skinner
Chris Skinner
3,807 Points

Error: connect ECONNREFUSED node.js https.get request to teamtreehouse.com/chalkers.json

Hi,

I'm running the first part of this video (the simple https request (I have updated my code to use https instead of http).

var https = require('https');

https.get('https://teamtreehouse.com/chalkers.json', function(response){
    console.dir(response);
});

When I try to console.dir the response I get the following error.

throw er; // Unhandles 'error' event
Error: connect ECONNREFUSED xxx.xx.xxx.xx:xxx

I'm sure this didn't happen the first time I ran through this course.(second time around now) I was using a mac the first time around by now on a PC, I don't see this making any difference though.

Not sure why this is happening..?!?

1 Answer

Chris Skinner
Chris Skinner
3,807 Points

I was behind a proxy and I came up with the following solution which allows me to connect to HTTPS from behind a proxy using request

const https = require('https');
const request = require('request');

request({
    'url':'https://teamtreehouse.com/chalkers.json',
    'proxy':'http://xx.xxx.xxx.xx'
    },
    function (error, response, body) {
        if (!error && response.statusCode == 200) {
            var data = body;
            console.log(data);
        }
    }
);

For reference for others, replace xx.xxx.xxx.xx with your proxy