0 votes
in JavaScript by
How middleware works in Express.Js?

1 Answer

0 votes
by

You could have multiple routes that match an incoming request.

Routes are executed from top to bottom.

If a route matches an incoming request, subsequent routes that match the incoming request won’t be hit if you don’t call next().

app.get('/', function(req, res) { console.log('one'); }); app.get('/', function(req, res) { console.log('two'); });

Here’s what will happen if there’s an incoming GET / request:

It will match the first route. The code in the first route will be executed. “The buck stops here”. Even though the second route matches the incoming request.

Related questions

0 votes
asked Mar 12, 2020 in JavaScript by GeorgeBell
0 votes
asked Oct 28, 2023 in ReactJS by DavidAnderson
...