In the following code, middleware logger()
is called twice if I put it as a first argument to app.use()
but it doesn't get called at all if put as a second argument.
Can someone please explain what's happening?
const express = require('express');
const app = express();
const path = require('path');
app.use(express.static(path.join(__dirname,'public')), logger);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Server started on port ${PORT}`));
function logger(req, res, next) {
console.log("logger, then next");
next();
}