Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js node_modules/express/lib/router/index.js:458抛出新的TypeError('router.use()需要一个中间件函数,但得到了'+gettype(fn))_Node.js_Express - Fatal编程技术网

Node.js node_modules/express/lib/router/index.js:458抛出新的TypeError('router.use()需要一个中间件函数,但得到了'+gettype(fn))

Node.js node_modules/express/lib/router/index.js:458抛出新的TypeError('router.use()需要一个中间件函数,但得到了'+gettype(fn)),node.js,express,Node.js,Express,我正在尝试创建nodejs express应用程序,在使用路由时遇到了奇怪的问题 这就是我的server.js的外观 const express = require('express'); const bodyParser = require('body-parser'); const path = require('path'); const http = require('http'); const api = require('./server/routes/api'); const a

我正在尝试创建nodejs express应用程序,在使用路由时遇到了奇怪的问题 这就是我的server.js的外观

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

const app = express();

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

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

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

const port = process.env.port || 3000;

app.set('port',port);
const server = http.createServer(app);
server.listen(port,function(){
console.log('server running at port '+port);
});
我得到以下错误节点\u modules/express/lib/router/index.js:458 抛出新的TypeError'Router.use需要一个中间件函数,但得到了一个'+gettypefn'


请告诉我哪里出了问题

我只是忘记在我的api.js中添加module.exports=router添加这个解决了我的问题