Answers for ""('Router.use() requires a middleware function""

Go
5

TypeError: Router.use() requires a middleware function but got a Object

module.exports = router;
Posted by: Guest on November-29-2020
0

TypeError: app.use() requires a middleware function

const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');

const app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());

// tells express which template engine to use
app.set('view engine', 'pug');

const routes = require('./routes');

app.use(routes);

app.use((req, res, next) => {
    console.log('Hello');
    next();
});
app.use((req, res, next) => {
    console.log("World");
    next();
});

app.use((req, res, next) => {
    const err = new Error('Not Found');
    err.status = 404;
    next(err);
});

app.use((err, req, res, next) => {
    res.locals.error = err;
    res.status(err.status);
    res.render('error');
});

app.listen(3000, () => {
    console.log('The application is running on localhost 3000');
});
Posted by: Guest on April-26-2020

Code answers related to ""('Router.use() requires a middleware function""

Browse Popular Code Answers by Language