12
rated 0 times
[
14]
[
2]
/ answers: 1 / hits: 54727
/ 6 Years ago, wed, august 22, 2018, 12:00:00
As per the node-fetch documentation node-fetch
we can get the response status like this
fetch('https://github.com/')
.then(res => {
console.log(res.status);
});
and for getting the data
fetch('https://api.github.com/users/github')
.then(res => res.json())
.then(jsonData => console.log(jsonData));
I have a scenario where I need to return the JSON data and the status from the response. I tried to use like this
fetch('https://api.github.com/users/github')
.then(res => res.json())
.then(jsonData => {
console.log(jsonData);
console.log(jsonData.status);
});
but the
console.log(jsonData.status)
won't return the status. How I can get status and output data
More From » node.js