Reputation: 209
Im new to node.js and consuming API's. Im following this tutorial for how to make a GET request but I keep getting this error:
Error: connect ECONNREFUSED 127.0.0.1:800 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect',
address: '127.0.0.1', port: 800 }
I'm not sure what to do now, any feedback is appreciated!
My 'DistributionList.js' file
const https = require("https");
const options = {
method: 'GET',
url: 'https://SomeApi.com/distributionLists',
headers: {
Authorization: "Bearer xyz",
Accept: "application/json"
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
Upvotes: 1
Views: 536
Reputation: 209
Removing the URL and replacing it with a host and path worked for me!
const https = require("https");
const options = {
method: 'GET',
host : 'SomeApi.com',
path: '/distributionLists',
headers: {
Authorization: "Bearer xyz",
Accept: "application/json"
}
}
const req = https.request(options, res => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', d => {
process.stdout.write(d)
})
})
req.on('error', error => {
console.error(error)
})
req.end()
Upvotes: 2