You have no installed phantomjs

I have PhantomJS installed, but I get an error (you don't have phantomjs installed) when I run my Node.js code:

var modules = '/home/engine/node_modules/';

var path = require('path');
var childProcess = require('child_process');
var phantom = require(modules+'phantom');
var binPath = phantom.path;

phantom.create(function(browser){ // Error happens here I think because the module is found
    // browser.createPage(function (page){});
});

If in console.log binPath I get undefined.

But in PuTTY, if I:

cd ~/phantomjs/
[root@engine phantomjs]# bin/phantomjs
phantomjs>

Did I install it in the wrong place?

+4
source share
4 answers

You need to load your global PhantomJS module, not the local one.

Downloading a local module prevents your application from finding the executable bit:

var phantom = require('phantom');

Plus by adding utnas comment:

Remove var modules = '/ home / engine / node_modules /'; . This is not useful. Node.js knows where to find the modules.

, Node.js , . , .

+3

macOS, .

brew install phantomjs
+4

. You don't have 'phantomjs' installed phantomjs- node. , :

var phantom = require('phantom');

var options = {
        path: '/usr/local/bin/'
};

phantom.create(function (ph) {
    ph.createPage(function (page) {
        page.open("http://www.google.com", function (status) {
            console.log("opened google? ", status);
            page.evaluate(function () { return document.title; }, function (result) {
                console.log('Page title is ' + result);
                ph.exit();
            });
        });
    });
}, options);

, options phantom.create(). path , phantomjs.

+1

Windows, - :

var phantom = require('phantom');

phantom.create(function (ph) {
  ph.createPage(function (page) {
     page.open("http://www.google.com", function (status) {
        console.log("opened google? ", status);
        page.evaluate(function () { return document.title; }, function  (result) {
            console.log('Page title is ' + result);
            ph.exit();
          });
        });
     });
    }, {
    dnodeOpts: {
       weak: false
    }
});
0

All Articles