爲什麼這段代碼不起作用? 如果我評論 fs.readFileSync('file.html'); 代碼工作,並創建文件「file.html」 但是,如果我去掉它fs.writeFileSync不工作,程序與錯誤崩潰:爲什麼我的fs.readFileSync不起作用
fs.js:427 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT, no such file or directory 'file.html' at Object.fs.openSync (fs.js:427:18) at Object.fs.readFileSync (fs.js:284:15) at Object. (/home/pedro/startupEngineering/hw3/Bitstarter/testrestler.js:15:6) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3
#!/usr/bin/env node
var fs = require('fs');
var rest = require('restler');
var restlerHtmlFile = function(Url) {
rest.get(Url).on('complete', function(result) {
fs.writeFileSync('file.html',result);
});
};
if(require.main == module) {
restlerHtmlFile('http://obscure-refuge-7370.herokuapp.com/');
fs.readFileSync('file.html');
}
else {
exports.checkHtmlFile = checkHtmlFile;
}
'沒有這樣的文件或目錄'file.html' – SLaks