Node.js & Express routing with parameters
问题 I currently have 2 routes in node.js for an API I am building. They are: app.get('/api/v1/user/:userid', function (req, res) { return res.status(200).json(GetUser()); }); and app.get('/api/v1/user', function (req, res) { return res.status(400).json('UserId expected'); }); As you can see, both routes actually should be combined into one, for example: app.get('/api/v1/user/:userid', function (req, res) { console.log('this should still show if :userid is not populated, but it does not'); if(!req