javascript CasperJS 中的文件 IO
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15283190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
File IO inside CasperJS
提问by AsTeR
Is it possible do read/write files inside a CasperJS Script ?
是否可以在 CasperJS 脚本中读/写文件?
var fs = require('fs');
var data = fs.readFileSync('testdata.data', 'utf-8');
console.log(data);
Calling casperjs fileio.js
returns:
调用casperjs fileio.js
返回:
'undefined' is not a function
Even after running npm install fs
.
即使在运行后npm install fs
。
Bonus point if not : explain why ?
加分点如果不是:解释为什么?
回答by hexid
CasperJS does not make use of NodeJS' fs
module. Instead, it uses that of PhantomJS
CasperJS 不使用 NodeJS 的fs
模块。相反,它使用了PhantomJS
Here's a short example of how to use PhantomJS' filesystem module:
这是如何使用 PhantomJS 的文件系统模块的简短示例:
var fs = require('fs');
var utils = require('utils');
var data = fs.read('testdata.dat');
utils.dump(data);