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.js
returns:
'undefined' is not a function
Even after running npm install fs
.
Bonus point if not : explain why ?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With