File IO inside CasperJS

柔情痞子 提交于 2020-01-11 15:47:09

问题


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 ?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!