Having trouble running Phantomjs + node on Heroku Having trouble running Phantomjs + node on Heroku heroku heroku

Having trouble running Phantomjs + node on Heroku


I've never used the phantomjs node module, but I do have an app running both node and phantomjs on Heroku.

You need to use custom buildpacks in order to get this to work. My .buildpacks file looks like

http://github.com/heroku/heroku-buildpack-nodejs.githttp://github.com/stomita/heroku-buildpack-phantomjs.git

You should then be able to run phantomjs scripts in a child process:

var script = app.get('root') + '/scripts/rasterize.js' //the phantomjs script to run  , bin = app.get('phantom') //normally this would just be the string "phantomjs"  , spawn = require('child_process').spawn;// set up args to the phantom cli// (run the phantomjs command in your terminal to see options/format)var args = [];// ...var phntm = spawn(bin, args);phntm.stdout.on('data', function (data) { /* do something */ });phntm.stderr.on('data', function (data) { /* do something */ });phntm.on('exit', function (code) { /* handle exit */ });


Heroku does not support WebSockets. With Socket.io it has a workaround. Not sure about dnode, which phantomjs-node uses.

I had a problem with WebSockets on Heroku too and I switched to Nodejitsu, which solved it for me.