I am trying to get data using curl on nodejs. I need to run more than one child_process for each query in order to retrieve the data without delays.
router.post('/curl/', function* () { var urls = this.request.body.url; var exec = require('child_process').exec; var promise = new Promise((resolve, reject) => { var count = urls.length; var res = _.map(urls, (stream) => { // stream = {url:'http://url1.com'}; var command = 'curl '+stream.url+'; exec(command, (error, stdout, stderr) => { if (error !== null) { console.log('exec error: ' + error); } return stdout; }); }); resolve(res); }); this.body = yield promise; }); This resolve '[null, null]'; I was tried to use Promise.map, but it was failed too.
If I make a single request (without _.map()) - it returns HTML of the requested page, as I expect. How to run more than one child_process for my requests?