phantomjs call from node.js uing spawn does not seem to execute script

rawcoder used Ask the Experts™
I am trying to generate a pdf file from a dynamic handlebar webpage that would display data from the database. Once I get this to work on my local machine, I would like to move the code up to elastic beanstalk. The code seems to run that initially makes the call to spawn, however, call to phantomjs does not seem to kick off the script passed to it. Just to confirm, I added a console.log statement at the very beginning of the file and never the print out. Not to mention the other print statement in the script file. The code is below:

code that performs the spawn:
var childArgs = [
                  path.join(__dirname, '../phantom/capture.js'),

            let child = spawn(phantomjs.path, childArgs, {detached: false});

            console.log('set up stderr.....');
            child.stderr.on('data', (data) => {
              console.log('ps stderr: ${data}');

            console.log('set up stdout.....');
            child.stdout.on('data', (data) => {
              console.log('ps stdout: ${data}');

            console.log('set up close.....');
            child.on('close', (code) => {
                console.log('this is a test 2.....');
                if (code !== 0){
                    let error = new Error('An error occurred while creating the current report.');
                    error.status = 500;


console.log('we are inside....');
let os = require('os');
var system = require('system');
console.log('we are inside.... 1');
var page = require('webpage').create();
let phantom = require('phantomjs-prebuilt');
console.log('we are inside....2');
var args = system.args;
console.log('we are inside....3');

if (args.length === 1) {
} else {
    page.viewportSize = { width: 2000, height: 800 };
//page.paperSize = { format: 'Letter', orientation: 'landscape', margin: '1cm' };
page.paperSize = { width: '1280px', height: '800px', margin: '0px' };
page.settings.localToRemoteUrlAccessEnabled = true;
page.settings.loadImages = true;
page.settings.javascriptEnabled = true;

let done = false;
//"" + args[1] + '?token=' + args[2]"" + args[1], function start(status) {
  if (status === "success"){
      page.render(os.tmpdir() + '/' + args[2], { format: 'pdf' });

  done = true;

var intervalId = setInterval(function(){
    if (done){
}, 100);

Open in new window

I am at a loss on where the problem can be. The first line of capture.js does not seem to get called. 1) What is the problem that I am missing? 2) How can I fix it?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial