javascript - throw new TypeError('Router.use() 需要一个中间件函数但得到一个' + gettype(fn))
问题描述
嘿伙计们,我知道以前有人问过这个问题,但我不明白,所以请大家帮忙
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))
解决方案
推荐阅读
- android - 我无法使用 Firebase 身份验证通过电子邮件和密码登录
- android - 从 Firebase 存储中删除图像时出错
- javascript - 如何附加由于函数而创建的元素?
- angular - angular 4 rerouting-component 不会重新加载
- php - 使用 .htaccess 删除 .php 扩展名会重复我的页面吗?
- ios - 如何使用 UITableView 在列表中创建列表
- python - 将列表从 pandas 列附加到 python 列表
- c# - Xamarin Android 将小部件工具栏图标向右对齐
- django - Django filter queryset __in exact matching
- python - 数据框列 str 替换为列表