I have created a mini function which searches for a keyword title and returns the title with that keyword included, it gets the correct data but spams the terminal with the same error over and over again.
const request=(url,cb)=>require('node-fetch')(url).then(res=>res.text()).then(data => cb(null,null,data), cb)
function script(keyword) {
request('https://hacker-news.firebaseio.com/v0/newstories.json?print=pretty', function(error, res, body){
let obj = JSON.parse(body);
for(let i = 0; i < obj.length; i++) {
request(`https://hacker-news.firebaseio.com/v0/item/${obj[i]}.json?print=pretty`, function(error, res, body){
let myData = JSON.parse(body);
var s = moment.unix(myData.time).format('LLLL');
var link = `https://news.ycombinator.com/item?id=${myData.id}`;
if(myData.title.includes(keyword)) {
client.hmset("requestedData", {Title: myData.title, Upvotes: myData.score, Date: s, URL: link})
client.hgetall("requestedData", function(err, reply) {
console.log(reply)
})
}
})
}
})
}
script("Software")
Error =>
(node:15992) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3795)