抛出新的TypeError('Router.use()需要中间件功能,但是得到了'+ gettype(fn))

时间:2018-07-25 19:48:32

标签: javascript node.js express

嘿,我知道有人问过这个问题,但是我不明白, 所以任何人都可以帮助

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;
const api = require('./server/routes/api');
const path = require('path');

app.use(express.static(path.join(__dirname, 'dist/todo')));

app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());

app.use('/api', api);

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

app.listen(port, () => console.log('server started'));

启动服务器时出现的错误

throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))

0 个答案:

没有答案