Express Route Handlers
Let’s look at the details of routing so that we can practice.
We'll cover the following...
In the previous lesson, we wrote the minimum code necessary to run the server and then accessed it through the browser.
Routes
Every application is usually divided into a bunch of routes. Any page or request we invoke on a website is hitting a specific route on the back-end server. Routes determine how each endpoint should be treated and what logic gets executed.
Each HTTP
request type is mapped to a routing method in Express with the syntax app.method(path, callback)
.
Route methods
The path defines the endpoint or the route path, for example, the / root
endpoint. After defining the endpoint, we then perform the matched callback
function. Here’s a list of the most common route methods:
- The
get
request handler is used to retrieve resources