【发布时间】:2015-12-10 05:20:49
【问题描述】:
我无法使用 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 程序
【问题讨论】:
-
我认为
sendFile是一种ExpressJS 响应方法。您需要安装和使用 Express 才能使用它。
标签: javascript node.js iis