我无法使用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仅在Express模块中。
试试这个代码
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.sendFile('path-to-file');
});
app.listen(PORT);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句