I'm trying to write a function that returns a series of Vote objects from the ProductHunt API on Node. I can access these objects but I don't know how to return them as the result of my function
var productHuntAPI = require('producthunt');
var productHunt = new productHuntAPI({
client_id: '123' ,// your client_id
client_secret: '123',// your client_secret
grant_type: 'client_credentials'
});
async function votesFromPage(product_id,pagenum){
var votes;
var params = {
post_id:product_id,
page:pagenum
};
productHunt.votes.index(params, async function (err,res) {
var jsonres= JSON.parse(res.body)
votes = jsonres.votes
console.log(votes)
})
return votes
}
async function main() {
var a = await votesFromPage('115640',1)
console.log('a is '+a)
}
main();
Logs:
a is undefined
[Array of Vote objects]
I'd like var a to contain the votes objects so I can use it