将phantomJS部署到node.js应用程序?

时间:2012-04-10 08:30:23

标签: node.js heroku phantomjs casperjs

我意识到"Running PhantomJS on Heroku"是一个相关但略有不同的问题,因为我正在尝试使用节点应用。

我在为节点应用程序部署casperJS(基于phantomJS)脚本时遇到问题。我已经尝试通过将PhantomJS 64位二进制文​​件放在我的应用程序的/bin目录中来部署到Heroku,但是当我尝试运行PhantomJS时出现以下错误:

phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory

从我读过的内容可以通过安装QtWebKit库来解决,但是Heroku没有安装它。是否有其他可以使用的托管服务提供商可以使用或在Heroku上安装此软件包的方法?

相关代码:

app.get('/', function(request, response) {
  var sys = require('sys')
  var exec = require('child_process').exec;
  var child;

  //works but gives error while loading shared library libqtwebkit.so.4
  child = exec("phantomjs --version | tr -d '\n'", function(error, stdout, stderr) {
    sys.print('stdout: ' + stdout);
    sys.print('stderr: ' + stderr + '\n');
    response.header('Content-Type', 'application/json');
    response.send('_testcb(stdout:' + stdout + '\nstderr:' + stderr + ')', 200);
    if(error !== null) {
      console.log('exec error: ' + error);
    }
  });
});

我已经注册了Nodester的beta测试,但他们的文档在这一点上仍然非常有限。

编辑:我只需将PhantomJS的lib文件夹复制到我的节点应用程序的根目录即可使其正常工作。

1 个答案:

答案 0 :(得分:3)

将phantomjs的lib文件夹复制到节点应用程序的根目录 您也可以尝试在bin或sbin中放入sym链接 关键是必须使用节点运行的同一帐户从终端运行。 此外,node-phantom是一个很好的npm库,可以在使用phantomjs后使用它。