I am not sure if I am missing a general understanding of the 'require' but if I try to include casperJs into a node child process I cannot use the module casper.
parent.js
var exec = require('child_process').exec;
for (var i = 0; i < 3; i++) {
exec('node child.js', {},
function(err, stdout, stderr) {
if (err) {
throw err;
}
console.log(stdout);
}
);
};
child.js
var casper = require('casper').create({
timeout: 180000
});
var meteorUrl = "http://hiddenURL/";
casper.start(meteorUrl, function(response) {
var _status = response.status;
if (_status == '200') {
this.echo("Page: " + meteorUrl + " loaded.");
} else {
this.die("Page not loaded! [" + _status + "]", 1);
}
});
casper.run();
Terminal
$ casperjs --version
1.1.0-beta3
$ casperjs child.js
Page: http://hiddenURL/ loaded.
$ node parent.js
Error: Cannot find module 'casper'
CasperJS is not a node.js module which is what the error message is actually saying. It is a standalone program that is only installed through NPM for convenience.
Change
to