我正在尝试使用nodejs的fs模块读取HTML文件内容 . 但是,我得到了TypeError .
有谁可以请知道我的代码中出了什么问题?
HTML代码 .
My Header
My paragraph
Nodejs代码
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
//Open a file on the server and return it's content:
fs.readFile('demofile1.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("Hey");
res.write(data);
return res.end();
});
}).listen(8080);
错误
_http_outgoing.js:457抛出新的TypeError('第一个参数必须是字符串或缓冲区'); ^ TypeError:第一个参数必须是在FSReqWrap的ReadFileContext.callback(D:\ Java \ Nodejs \ public \ readfile.js:8:9)的ServerResponse.OutgoingMessage.write(_http_outgoing.js:457:11)处的字符串或缓冲区.readFileAfterOpen [as oncomplete](fs.js:366:13)