How can you define optional route parameters in Express.js?

  • Enclose parameters in square brackets [param]
  • Use the optional keyword before the parameter
  • Use the ? symbol after the parameter
  • Wrap parameters in parentheses (param)
In Express.js, you can define optional route parameters by using the ? symbol after the parameter name, like /route/:param?. This makes the parameter optional, allowing it to match both routes with and without that parameter. The other options do not represent the correct way to define optional route parameters in Express.js.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *