Express router - :id?
On your code, that is for express framework middleware, if you want to get any id in the server code using that route, you will get that id by req.params.id
.
app.use('/todos/:id', function (req, res, next) {
console.log('Request Id:', req.params.id);
next();
});
Route path: /student/:studentID/books/:bookId
Request URL: http://localhost:xxxx/student/34/books/2424
req.params: { "studentID": "34", "bookId": "2424" }
app.get('/student/:studentID/books/:bookId', function (req, res) {
res.send(req.params);
});
Similarly for your code:
Route path: /todos/:id
Request URL: http://localhost:xxxx/todos/36
req.params: { "id": "36" }
app.use('/todos/:id', function (req, res, next) {
console.log('Request Id:', req.params.id);
next();
});
This is an express middleware.
In this case, yes, it will route /todos/anything
, and then req.params.id
will be set to 'anything'