Languages
[Edit]
EN

Express.js - route parameters

0 points
Created by:
Kadeem-Craig
516

In this article, we would like to show you how to use route parameters in Express.js.

Introduction

Edit

Route parameters are named URL segments that are used to get the values specified at their position in the URL. The received values are stored in the req.params object, with the name of the route parameter specified in the path as their respective keys.

Practical example

Edit

In below example, we define route for users with specified route parameter used get user by id. For now we just use it to send back the parameter (req.params).

Result:

Node.js / Express.js - server response
Node.js / Express.js - server response

As you can see, we passed 12 as a user id parameter and received proper req.params object as a response.

Note:

The name of route parameters must be made up of “word characters” ([A-Za-z0-9_]).

References

Edit
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join