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.
Loading...
Related Quiz
- What is the primary difference between null and undefined in JavaScript?
- You are tasked with developing a system to read and process large files without consuming a lot of memory. How would you utilize streams in Node.js to efficiently read, process, and write the data?
- Which of the following stream types is used for reading data in Node.js?
-
Developers can use npm deprecate
[@ ] to mark a package or a specific version as deprecated, displaying a warning message ______ to any developers installing it. - The aud claim in a JWT token represents the ________ for which the JWT is intended.