Skip to content

Instantly share code, notes, and snippets.

@valerianpereira
Created October 10, 2018 07:21
Show Gist options
  • Save valerianpereira/9ec2c0eabd5bb227aeb285afb151bb57 to your computer and use it in GitHub Desktop.
Save valerianpereira/9ec2c0eabd5bb227aeb285afb151bb57 to your computer and use it in GitHub Desktop.
Making an API call in NodeJs using https package
const https = require('https');
const URL = 'You can find http API url from https://indianrailapi.com/api-collection';
https.get(URL, (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data));
});
}).on("error", (err) => {
console.error("Error: " + err.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment