glog glog - 5 months ago 40
Node.js Question

Express router - :id?

Real simple question guys: I see a lot of books/code snippets use the following syntax in the router:

app.use('/todos/:id', function (req, res, next) {
console.log('Request Type:', req.method);

I'm not sure how to interpret the route here... will it route '/todos/anything'? and then grab the 'anything' and treat is at variable ID? how do I use that variable? I'm sure this is a quick answer, I just haven't seen this syntax before.

Answer Source

This is an express middleware.

In this case, yes, it will route /todos/anything, and then will be set to 'anything'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download