问题
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 ?
回答1:
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);
来源:https://stackoverflow.com/questions/15283190/file-io-inside-casperjs