Express.js: how to make app.get ('/ [: userId] i' ..) in req.param?

I am using nodejs 0.8.21 and expressing 3.1.0

I need to read userIdfrom url how http://mysite.com/39i. That means userId=39. How to do? Thank. Example:

app.get('/:userId_i', function(req, res) { });
app.param('userId', function(req, res, next, id){ });
+5
source share
1 answer

Assuming you have a numeric identifier followed by iand you want the identifier to be returned as numeric only.

app.get("/:id([0-9]+)i", function (req, res) {...});

This will match the number that follows i, and you will only get a numeric value in req.params.id.

Example:

curl -XGET localhost:8080/124i

Gives me the following in req.params

[ 'id': 124 ]
+10
source

All Articles