yarek
yarek

Reputation: 12044

casperjs: can I use node packages inside casperjs with 'require' keyword?

I do use casperjs. I need to use some ready to go node packagages with casperjs such as: https://www.npmjs.com/package/csv-write-stream to create CSV files

inside my capserjs file I have:

var fs = require('fs'); // this works
var system = require('system'); // this works
var csvWriter = require('csv-write-stream'); // stops the script, no error, it  works fine with nodejs script
var writer = csvWriter()

It looks like some require are ok (system, fs), but not 'csv-write-stream'

I would like to understand if (I can/how I can) use require packages in casperjs ?

I found that:

CasperJS allows using nodejs modules installed through npm. Note that since CasperJS uses it’s own JavaScript environment, npm modules that use node-specific features will not work under CasperJS.

So how to determine which module will work ?

Upvotes: 0

Views: 429

Answers (1)

Sayalic
Sayalic

Reputation: 7650

From official documentation:

CasperJS allows using nodejs modules installed through npm. Note that since CasperJS uses it’s own JavaScript environment, npm modules that use node-specific features will not work under CasperJS.

So, you can try any node module which you want to import and test it works or not...

As Artjom B pointed out, fs and system are phantomjs modules. And all phantomjs module is listed here.

Upvotes: 1

Related Questions