[go: up one dir, main page]

0% found this document useful (0 votes)
45 views2 pages

Matching Route Paths

Express matches incoming requests to registered routes in the order they are defined in the code. If a request matches a route, its callback is executed to send a response; otherwise, a 404 Not Found response is returned if no routes match. The document provides an example illustrating how Express processes routes sequentially.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

Matching Route Paths

Express matches incoming requests to registered routes in the order they are defined in the code. If a request matches a route, its callback is executed to send a response; otherwise, a 404 Not Found response is returned if no routes match. The document provides an example illustrating how Express processes routes sequentially.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Matching Route Paths

3 min
Express tries to match requests by route, meaning that if we send a request
to <server address>:<port number>/api-endpoint, the Express server will search
through any registered routes in order and try to match /api-endpoint.

Express searches through routes in the order that they are registered in your
code. The first one that is matched will be used, and its callback will be called.

In the example to the right, you can see two .get() routes registered at /another-
route and /expressions. When a GET /expressions request arrives to the Express
server, it first checks /another-route‘s path because it is registered before
the /expressions route. Because /another-route does not match the path, Express
moves on to the next registered middleware. Since the route matches the
path, the callback is invoked, and it sends a response.

If there are no matching routes registered, or the Express server has not sent a
response at the end of all matched routes, it will automatically send back a
404 Not Found response, meaning that no routes were matched or no
response was ultimately sent by the registered routes.

Instructions

Move on to the next exercise when you’re ready.

You might also like