I am just trying to send a get request to an API. I get a 200 response, but none of the callback functions seem to be happening, including end. Here is the relevant section, I also have the rest of the express server up, and the server is running.
var https = require("https");
https.get("https://tfe-opendata.com/api/v1/stops", function(res){
console.log("Response: ", res.statusCode);
console.log("Res: " + res);
}).on('data', function(data) {
console.log('blah');
console.log("data: " + data);
process.stdout.write(data);
}).on('error', function(error) {
console.error('Error ' + error);
}).on('end', function(){
console.log("End.");
});
It should just return JSON, and you can see the data and url are valid if you go to the address. None of the prints after the first callback happen.
Edit: It works if I use the full https.request method
var options = {
host: 'tfe-opendata.com',
path: '/api/v1/stops',
method: 'GET'
}
var httpreq = https.request(options, function(response) {
response.on('data', function(chunk) {
console.log("data " + chunk);
});
});
httpreq.on('error', function(e) {
console.log('error: ' + e);
});
httpreq.end();
I still don't know why the original didn't work.