嘿,我知道有人问过这个问题,但是我不明白, 所以任何人都可以帮助
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))