How to use Node.js to write client-side application

nwagh404nwagh404 Member
edited March 2018 in Review my code

I'm getting an error

Got error: connect ECONNREFUSED

I'm not sure what is going wrong. I have given the headers too, is there anything else I have to take care of? I'm a newbie please help.
Here is my code.

    const options = {
                headers: {
                    'Accept' : 'application/json',
                    'app_id' : 'my_ID',
                    'app_key': 'my_key'
                uri : "",
                method : 'GET'

            const req = https.request(options, (res) => {
                console.log('statusCode:', res.statusCode);
                console.log('headers:', res.headers);

                res.on('data', (d) => {
                    console.log('Data', d);

            req.on('error', (e) => {

Best Answers

  • AmosDuveenAmosDuveen admin
    Accepted Answer

    Hi @nwagh404,

    FYI: I have removed the link you posted to protect your credentials.

    Have you had a read through this thread yet?


  • AmosDuveenAmosDuveen Member, Administrator, Moderator admin

    I'd better start with the most basic errors and work from there: have you made sure to replace the app_id and app_key with the correct credentials?

    They should have been emailed to you when you signed up for an account and look similar to the ones you see on our documentation page (which don't work on the live version of the API):
    "app_id": "5037d509",
    "app_key": "4dc1aebaa63721f0f8e79a55e2514bc7"

  • nwagh404nwagh404 Member
    edited March 2018

    @AmosDuveen Yes I have replaced them with proper app_id and proper app_key. I just put it that way to keep my secrets private.
    I tried the python code given in the documentation, it is working for my secrets , but the same request is not working in Node.js

  • AmosDuveenAmosDuveen Member, Administrator, Moderator admin
    edited March 2018

    Hi @nwagh404,

    Understood, but I have to ask, just in case! Could you please copy/paste the exact error message you are receiving?

  • nwagh404nwagh404 Member
    edited March 2018

    @AmosDuveen This is the error I'm getting:

    { Error: connect ECONNREFUSED
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect',
    address: '',
    port: 443 }

Sign In or Register to comment.