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(); }
https://stackoverflow.com/questions/65855889/expressjs-middleware-is-being-called-twice January 23, 2021 at 12:58PM
没有评论:
发表评论