const express = require('express');
const app = express();
app.use('/', (req, res, next) => {
console.log('This always runs!');
next();
});
app.use('/add-product', (req, res, next) => {
console.log('In add product middleware!');
res.send('<h1>The "Add Product" Page</h1>');
});
app.use('/', (req, res, next) => {
console.log('In another middleware!');
res.send('<h1>Hello from Express!</h1>');
});
app.listen(3000);
NodeJS / Express: what is "app.use"? I read from this post and still confused about how the flow-of-control goes in this program.How come if I visit "localhost:3000/add-product" the result logged is "This always runs!In add product middleware!This always runs!In another middleware!"(I omitted the changeline) Does this mean after it goes into the second app.use,and as I've learnt,each app.use(middleware) is called every time a request is sent to the server.So this process restarts,but why this time next() would result in the third app.use being called?I thought next would go into the next matching path..