Reputation: 1114
i have the following very simple code:
var phantom = require('phantomjs');
phantom.create(function(ph){
ph.createPage(function(page) {
page.open("http://www.google.com", function(status) {
page.render('google.pdf', function(){
console.log('Page Rendered');
ph.exit();
});
});
});
});
When i run this i get an undefined is not a function
error at the line phantom.create()
I am right now sitting on a windows machine and read somewhere that i might have to use something called dnode
my question is could this be the cause of the error or is there something in the code that might be wrong?
Update
I've changed var phantom = requiere(phantomjs)
to be var phantom = requiere(phantom)
, but now i get the error:
phantom stderr: 'phantomjs' is not recognised as an internal or external kommand, a program or a batchfil.
...
AssertionError: abnormal phantomjs exit code: 1
Upvotes: 1
Views: 303
Reputation: 38519
You're getting mixed up between phantomjs
and phantom
node.js modules.
Your code follows the phantom
module's pattern it looks like: https://www.npmjs.com/package/phantom
(this is a node wrapper for phantomjs)
So, require phantom, instead of phantomjs
Be sure to have run npm install phantom
before this
var phantom = require('phantom'); //not phantomjs
phantom.create(function(ph){
ph.createPage(function(page) {
page.open("http://www.google.com", function(status) {
page.render('google.pdf', function(){
console.log('Page Rendered');
ph.exit();
});
});
});
});
Upvotes: 2