Search code examples
node.jsgetrequestgithub-apieconnrefused

Node.js Github API connect ECONNREFUSED error getting user repos


I'm locally attempting to get user repos via https get request with https.get

const https = require("https")

https.get({
    url: "https://api.github.com/users/ryanve/repos"
  }, response => {
    let data = ""
    response
      .on("data", chunk => data += chunk)
      .on("end", () => {
        console.log(data)
      })
  })
  .on("error", e => {
    console.error(e.message)
  })

I get an ECONNREFUSED error

connect ECONNREFUSED 127.0.0.1:443

What causes this error?

Authentication?

How do I fix?

node --version is v12.16.2


Solution

  • You can't include url in an object that you pass to get. Since that's all you passed and it was ignored, it used a default URL of localhost. (IMO, having a default URL and not just throwing an error saying a URL is missing is a wart in NodeJS, but that's neither here nor there.) Replace this:

    https.get({
        url: "https://api.github.com/users/ryanve/repos"
      }
    

    With this:

    https.get("https://api.github.com/users/ryanve/repos"