0

I am trying to create a NodeJS program that utilizes CasperJS within it. I have run into the error that the module 'casper' cannot be found. As a result, I have tried to npm install spooky --save as I have read around that it is a driver, but I am still getting the same error as I was getting before.

Also, before trying to install SpookyJS, I tried

 var phantom = require('phantom');

 phantom.casperPath = '/path/to/casperjs';
 phantom.injectJs(phantom.casperPath + '/bin/bootstrap.js');

Which then gave me the error that injectJs is not a function. Any and all help appreciated.

Gabe Gomez
  • 81
  • 2
  • 11

2 Answers2

0

you can't include js files to phantom. you need to open a page and then you can includejs into it. page will accept js files. not phantom.

Please refer this

includeJs(url, callback) {void}

Includes external script from the specified url (usually a remote location) on the page and executes the callback upon completion.

Dinesh undefined
  • 5,490
  • 2
  • 19
  • 40
  • I have looked into your solution, but I am now getting the error that the webpage module. I looked around and understand that it is a module of PhantomJS and not NodeJS, but that literally doesn't help me at all in order to figure out what's going on. – Gabe Gomez May 25 '17 at 15:12
  • ^webpage module can not be found* – Gabe Gomez May 25 '17 at 15:20
0

First of all, to contextualize a bit, here is an important reminder for everyone:

While CasperJS is installable via npm, it is not a NodeJS module and will not work with NodeJS out of the box. You cannot load casper by using require(‘casperjs’) in node. Note that CasperJS is not capable of using a vast majority of NodeJS modules out there. Experiment and use your best judgement.

This is where SpookyJS comes into play... But how to make it work? (I assume you are on Linux.)

1. Make sure you have the right environment

  • Node.js >= 0.8
  • PhantomJS >= 1.9
  • CasperJS >= 1.0

Note: SpookyJS works on my computer (Arch Linux) and I have the following setup:

node --version ---> v7.7.4
npm --version ---> 4.4.4
phantomjs --version ---> 2.1.1
casperjs --version ---> 1.1.3

PhantomJS and CasperJS are installed globally.

2. Install SpookyJS locally (and its dependency: tiny-jsonrpc)

Create an empty directory and run npm i spooky tiny-jsonrpc inside. We do not need a package.json here, so you can forget about --save or --save-dev.

3. Test the given example

If SpookyJS is installed, you should have a local node_modules directory. Now, try to run the following command:

node node_modules/spooky/examples/hello.js

If you get "Hello, from Spooky the Tuff Little Ghost - Wikipedia", congrats! You can now integrate SpookyJS in your project, but you will have to respect the syntax presented in hello.js...

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
  • Thanks for the suggestion, but I am now running into the problem that 'spooky.start' is not a function. The node function for the command you put in ran as well. – Gabe Gomez May 26 '17 at 06:09
  • What do you get when you run `node node_modules/spooky/examples/hello.js`? If you get an error here, it means that SpookyJS is not installed properly... – Badacadabra May 26 '17 at 18:25
  • I get the message "Hello, from Spooky the Tuff Little Ghost - Wikipedia". Copied and pasted from the terminal it ran from. Is possible that there is a slight difference when running on Mac? – Gabe Gomez May 26 '17 at 19:46
  • Cool. Spooky works on your system. Now use `hello.js` as a reference for your own script... Did you read the code in this file? – Badacadabra May 26 '17 at 19:52
  • Ahh I see now. Got impatient and ain't read the whole way through for sure lol. Thank you very much. – Gabe Gomez May 26 '17 at 23:45