TypeError:res.status(...)。sendFile不是一个函数

时间:2018-09-24 19:59:33

标签: javascript express

我是这方面的初学者,因此,如果这很容易解决,我深表歉意。但是我收到下面的错误。

TypeError: res.status(...).sendFile is not a function
    at app.get (/root/discordtest/server.js:10:19)
    at callbacks (/root/node_modules/express/lib/router/index.js:164:37)
    at param (/root/node_modules/express/lib/router/index.js:138:11)
    at pass (/root/node_modules/express/lib/router/index.js:145:5)
    at Router._dispatch (/root/node_modules/express/lib/router/index.js:173:5)
    at Object.router [as handle] (/root/node_modules/express/lib/router/index.js:33:10)
    at next (/root/node_modules/connect/lib/proto.js:174:15)
    at next (/root/node_modules/connect/lib/proto.js:149:78)
    at Object.expressInit [as handle] (/root/node_modules/express/lib/middleware.js:30:5)
    at next (/root/node_modules/connect/lib/proto.js:174:15)

我正在使用的代码是:

const express = require('express');
const path = require('path');
const app = express();

// Routes
app.use('/api/discord', require('./api/discord'));

app.get('/', (req, res) => {
  res.status(200).sendFile(path.join(__dirname, 'index.html'));
});

app.listen(50451, () => {
  console.info('Running on port 50451');
});

1 个答案:

答案 0 :(得分:0)

检查您的版本。 Express v4.8.0及更高版本支持res.sendFile()