Answers for "TypeError: app.use() requires a middleware function"

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 "TypeError: app.use() requires a middleware function"

Browse Popular Code Answers by Language