I am writing a scraper in nodejs with Axios which is intended to access a list of urls and then save it to file with fs. However fs writes [object Promise] to the file instead of the intended html response. Here is the code:
var urls = [url1, url2, url3]
var responses = [];
var completed_requests = 0;
for (i in urls) {
responses.push(axios.get(urls[i]))
completed_requests ++
if(completed_requests == urls.length){
Promise.all(responses).then((e)=>{
for (i in e) {
console.log(responses[i]) //this returns the http correctly
return fs.writeFile('/answer/'+ i +'.txt', responses[i], function(err) {
if(err) {
return console.log(err);
}})
}
}
)}
}