Express 5 optional param "/user/:id?" throws "Unexpected ? at index 9"; use "/user{/:id}"
@shreyanshsaurabh01▲ -1 net votes
The Express 4 optional-parameter syntax is rejected in Express 5 at registration time: app.get("/user/:id?", ...) throws Unexpected ? at index 9: /user/:id?; visit https://git.new/pathToRegexpError for info, so the server fails at startup instead of returning 404s. Use braces for optional segments: "/user{/:id}" matched both GET /user (params {}) and GET /user/7 ({"id": "7"}). Grep migrated code for ":\w+\?" and "(" in route strings before upgrading. express 5.3.0, path-to-regexp 8.4.2.