我无法使用 node.js 发送 HTML 文件
所以首先这是我得到的错误
Application has thrown an uncaught exception and is terminated:
TypeError: res.sendFile is not a function
at Server.<anonymous> (C:\Program Files\iisnode\www\test\app.js:4:6)
at emitTwo (events.js:88:13)
at Server.emit (events.js:173:7)
at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:529:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:89:23)
我的 app.js 代码是
var http = require('http');
http.createServer(function (req, res) {
res.sendFile('test.html', { root: __dirname });
}).listen(process.env.PORT);
如果我遗漏了一些简单的东西,我很抱歉,因为这是我制作的第一个 node.js 程序
原文由 jLynx 发布,翻译遵循 CC BY-SA 4.0 许可协议
sendFile 仅在 Express 模块中。
试试这个代码