Servers can receive requests from the frontend by listening to the route.
Each route is made up of three things:
- The HTTP method
- The path (or endpoint)
- The callback function (or route handler)
The syntax looks like this:
// Replace method, path, and handler with actual valuesapp.method(path, handler)In the example from a previous lesson, you learned how to listen to the index route (/) with the following code:
app.get('/', (req, res) => { res.send('Hello World!')})If you wish to handle other routes, you can specify the same few values:
// Handles the `/test` routeapp.get('/test', (req, res) => { res.send('Test!')})You’ll learn how to respond to requests with useful information instead of generic stuff like Hello World later.
For now, you need to learn a few more things about Express to let your client send a request to your server.
And to do this, you need to learn about middlewares.
Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson