K
K
KIberWarriorJs2022-01-29 13:27:14
Node.js
KIberWarriorJs, 2022-01-29 13:27:14

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

1 answer(s)
R
Rag'n' Code Man, 2022-01-29
@KIberWarriorJs

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 question

Ask a Question

731 491 924 answers to any question