I'm trying to call a node script from a PHP script using exec
:
$output = exec("/usr/bin/node /home/user/nodescript.js");
The nodescript.js being:
var Scraper = require('google-images-scraper');
var keywords = process.argv[2];
var scraper = new Scraper({
keyword: keywords,
rlimit: 10, // 10 p second
});
console.log("foo");
scraper.list(10).then(function (res) {
console.log("bar");
console.log(res);
});
setTimeout(function () {
process.exit(1);
}, 20000)
But what I receive is the string "foo", and not the "bar". If I run the node script from command line, I do get "foo" and "bar". Somehow I don't receive any console output inside the function. What am I doing wrong?