Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems directly using PhantomJS in node.js

I'm attempting to use PhantomJS, and I've installed it via NPM. I can't seem to run any of the of the examples, in fact I can't even run:

var page = require('webpage').create();

I get the error:

Error: Cannot find module 'webpage'

Is there anything i'm missing? I'm using a few other modules that I've installed via NPM in the same directory with no issues

like image 668
1dayitwillmake Avatar asked Mar 18 '13 21:03

1dayitwillmake


People also ask

For which application node JS is not suitable?

Not Suitable for Heavy-Computing Apps Node. js doesn't support multi-threaded programming yet. It is able to serve way more complicated applications than Ruby, but it's not suitable for performing long-running calculations. Heavy computations block the incoming requests, which can lead to decrease of performance .

What is the use of PhantomJS?

PhantomJS is a discontinued headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment.

Is node js the best platform for CPU heavy applications Why?

js for CPU-intensive operations; in fact, using it for heavy computation will annul nearly all of its advantages. Where Node really shines is in building fast, scalable network applications, as it's capable of handling a huge number of simultaneous connections with high throughput, which equates to high scalability.

What are the reasons for node js being lightweight and efficient?

Node JS uses an asynchronous event-driven I/O model, ensuring that almost no function in Node directly performs I/O. That makes it lightweight and efficient.

How to work with PhantomJS in Node JS?

If you want to use a module to work with PhantomJS in Node.js, you can use the phantom module written by @amir20. This module offers integration for PhantomJS in Node.js. Although the workflow with Javascript ain't the same that the Javascript that you use to instruct PhantomJS, it's still easy to understand.

What are the problems with converting HTML to PDF using NodeJS/PhantomJS?

There are some html and CSS issues which you might face while generating/converting your html to PDF using nodejs and Phantomjs. 1. Problem in including Bootstrap library if you are using bootstrap in your html and you are using the library in your folder and setting it's path it might not work.

Why is PhantomJS not working on https?

Thus, if PhantomJS works well with HTTP but it shows some problem when using HTTPS, the first useful thing to check it whether the SSL libraries, usually OpenSSL, have been installed properly. On Windows, the default proxy setting may cause a massive network latency (see Known Issues in the release note).

Why are some PhantomJS examples not working in the terminal?

If some examples do not work, make sure that there is not more than one version of PhantomJS installed in the system. Multiple versions may lead to conflict as to which one is being invoked in the terminal.


Video Answer


1 Answers

PhantomJS is not for Node.js. You are likely running the examples through node binary.

Read the Getting Started documentation carefully and you'll see that every single PhantomJS example need to be invoked like:

phantomjs hello.js

Note that there is a bridge between Node.js and PhantomJS. In that case, you need to follow the given examples for that particular bridge (there are a few different ones).

like image 68
Ariya Hidayat Avatar answered Oct 21 '22 17:10

Ariya Hidayat