دنبال کننده ها

۱۳۹۶ اسفند ۱۲, شنبه

node.js - node_modules/express/lib/router/index.js:458 throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))

[ad_1]



I am trying to create nodejs express application, I am facing weird issue while using routes
This is how my server.js looks



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);
);


I am getting following error "node_modules/express/lib/router/index.js:458
throw new TypeError('Router.use() requires a middleware function but got a ' + gettype(fn))
"



Please let me know where I am going wrong




[ad_2]

لینک منبع