I am trying to get data from an api in Nodejs and put it in a variable, once I get that data I would use different bits of it such as the people who are in space.
I am struggling to find out how here is my code:
const request = require("request")
let url = 'http://api.open-notify.org/astros.json';
let data = request(url, (error, response, body) => {
let data;
if (!error && response.statusCode == 200) {
data = body
}
return data
})
console.log(data)
My output