I am trying to get a JSON from https://api.nal.usda.gov/fdc/v1/foods/search?api_key=DEMO_KEY&query=ketchup and do something with it by storing it into a variable. I used Node and Express in my work. Can anyone please tell me how to. Very much appreciated, Thanks.
-
Can you show your code? Please review this question on how to do a minimum reproducible example, for a better experience to help you. stackoverflow.com/help/minimal-reproducible-exampleDanizavtz– Danizavtz2020-06-14 05:49:04 +00:00Commented Jun 14, 2020 at 5:49
-
you can use, axios or got or SuperAgent or Request or HTTP-the Standard Library in nodejsTaher Fattahi Tabalvandan– Taher Fattahi Tabalvandan2020-06-14 06:41:19 +00:00Commented Jun 14, 2020 at 6:41
Add a comment
|
1 Answer
I asume that your server is working and fetching data correctly. Then you can use something like that:
async function getData() {
return fetch('https://api.nal.usda.gov/fdc/v1/foods/search?api_key=DEMO_KEY&query=ketchup')
.then(response => response.json())
}
getData()
.then(data => console.log(data))
Like zinkn say here