I have a simple express server that is running a loop checking every domain in an array.. Right now I'm pushing all of the results into an array results
on every .then
statement of the promise. How would I then send the results
in server response after this promise block completes? Should I run a callback with res.send(results) after the promise? Or is there a way to do it from inside the promise with .finally?? Or should i be using the express next
parameter? I'm not sure how to do this.
const whois = require('whois-info');
const express = require('express');
const app = express();
app.get('/domainfinder/domain/:domainURL', (req, res) => {
//const domainURLs = req.params.domainURLs;
let tests = ['google.com', 'nomatchdomain.com', 'notfounddomain.me'];
let results = [];
[...tests].forEach(domain => {
whois.lookup(domain)
.then(data => results.push(data))
.catch(e => console.log(domain, e.message))
});
res.send(results);
});
app.listen(3000, () => console.log('App listening on port 3000!'));