Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File IO inside CasperJS

Tags:

Is it possible do read/write files inside a CasperJS Script ?

var fs = require('fs'); var data = fs.readFileSync('testdata.data', 'utf-8'); console.log(data); 

Calling casperjs fileio.jsreturns:

'undefined' is not a function 

Even after running npm install fs.

Bonus point if not : explain why ?

like image 505
AsTeR Avatar asked Mar 07 '13 22:03

AsTeR


1 Answers

CasperJS does not make use of NodeJS' fs module. Instead, it uses that of PhantomJS

Here's a short example of how to use PhantomJS' filesystem module:

var fs = require('fs'); var utils = require('utils'); var data = fs.read('testdata.dat'); utils.dump(data); 
like image 67
hexid Avatar answered Sep 20 '22 19:09

hexid