const got = require('got');
const url = 'https://api.wmata.com/Incidents.svc/json/Incidents';
(async () => {
try {
const response = await got(url, {
headers: {
'api_key': process.env.myApiKey
}
});
console.log(response.body);
//=> '<!doctype html> ...'
} catch (error) {
console.log(error.response.body);
//=> 'Internal server error ...'
}
})();