Answer the question
In order to leave comments, you need to log in
Why is the route not running in node js ( express )?
Hello everyone , there is such a code . Because of what, the code on the localhost:3000/stories route may not be executed
import express from 'express';
const port = process.env.PORT || 3000;
const app = express();
const myLogger = (req, res, next) => {
console.log('LOGGED', new Date());
};
app.use(myLogger); // application level middleware
app.get('/', (req, res) => {
res.send('Hello World!z');
});
app.get('/stories', (req, res) => {
res.send('Hello World!123');
});
app.listen(port);
Answer the question
In order to leave comments, you need to log in
You must call next()
in your logging middleware. The code just doesn't go further down the chain.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question