Files
freeCodeCamp/curriculum/challenges/english/blocks/lecture-understanding-routing-in-express-js/69a9182c1bc7cc1a76116635.md
T
2026-04-24 18:25:01 +00:00

3.2 KiB
Raw Blame History

id, title, challengeType, dashedName
id title challengeType dashedName
69a9182c1bc7cc1a76116635 What Are Route Paths in Express? 19 what-are-route-paths-in-express

--description--

In Express, route paths are the URL patterns that determine how the server responds to incoming requests. When a user requests a specific URL, Express matches that URL to a route path and runs the corresponding handler.

Route paths are defined inside route methods like app.get(), app.post(), and so on. These paths can be static, such as /home, or dynamic, where parameters are used to capture values from the URL, like /user/:id.

In this lesson well focus on static routes. Heres an example of one:

// Static route
app.get("/home", (req, res) => {
  res.send("Welcome to the homepage!");
});

In this example, the server listens for GET requests to /home and responds with a simple message.

The app.get() method takes two arguments:

  • The first argument, "/home", is the static route path (or URL) that the server listens for.

  • The second argument is a callback function that runs when a GET request is made to that path.

Inside the callback, res.send() sends a response back to the client. In this case, it sends the text Welcome to the homepage!, which is displayed in the browser.

Heres another example of a static route:

// Static route
app.get("/menu/drinks", (req, res) => {
  res.send("Welcome to the drinks menu!");
});

In this case, the server listens for GET requests to the /menu/drinks URL and sends back a message when that route is requested.

You might use routes like this when your site has multiple related pages grouped under a common path. For example, a restaurant website could organize its menu pages like this:

  • /menu/food

  • /menu/drinks

  • /menu/desserts

This approach helps keep your URLs clear and meaningful, and it also makes your routes easier to organize and maintain as your application grows.

In the next lesson, well look at dynamic route paths with parameters.

--questions--

--text--

What does the route app.get("/home", ...) respond to?

--answers--

POST requests to /home

--feedback--

Look at the first parameter.


GET requests to /home


GET requests to /menu/drinks

--feedback--

Look at the first parameter.


POST requests to /menu/drinks

--feedback--

Look at the first parameter.

--video-solution--

2

--text--

What does the route app.get("/menu", ...) respond to?

--answers--

POST requests to /menu

--feedback--

Look at the first parameter.


GET requests to /menu


GET requests to /menu/drinks

--feedback--

Look at the first parameter.


POST requests to /menu/drinks

--feedback--

Look at the first parameter.

--video-solution--

2

--text--

What does the route app.get("/menu/drinks", ...) respond to?

--answers--

POST requests to /menu

--feedback--

Look at the first parameter.


GET requests to /menu

--feedback--

Look at the first parameter.


GET requests to /menu/drinks


POST requests to /menu/drinks

--feedback--

Look at the first parameter.

--video-solution--

3