I am trying to make a Project using news API and I keep getting userAgentMissing error. I've tried few things but I couldn't figure out what I am doing wrong. i've tried using https.request method as well but result was the same.
app.get("/", function (req, res) {
let url = "https://newsapi.org/v2/top-headlines?country=in&apiKey=xxxxx";
https.get(url, function (response) {
console.log(response.statusCode);
response.on('data', function (data) {
const recievedData = JSON.parse(data);
console.log(recievedData);
});
});
});
And here's the error I am getting.
400
{
status: 'error',
code: 'userAgentMissing',
message: 'Please set your User-Agent header to identify your application. Anonymous requests are not allowed.'
}