Languages
[Edit]
EN

Express.js - wildcard parameters in routing path

10 points
Created by:
Imaan-Morin
1009

In this short article, we would like to show how to use wildcard parameters in routing path in Express.js.

Express.js allows to use wildcard parameters in routing paths by inserting star characters (*). Sometimes it is necessary to get not decoded wildcard parameter values. By default Express.js do not let to get not decoded parameters so some trick related with path-to-regexp package is needed, what was show as case examples.

The below examples were tested using Express.js v4.18.2.

 

Simple example

Edit

In this section we focus on /path/to/* paht as example.

 

Complex example

Edit

In this section we focus on /path/to/a-*/b-*/etc paht as example.

Motivation: this solution finds application when we want to forward parameters to other logic, e.g. proxy.

 

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