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

后端 未结 1 919
-上瘾入骨i
-上瘾入骨i 2021-01-05 22:03

I m using nodejs 0.8.21 and express 3.1.0

I need to read userId from url like http://mysite.com/39i. It means userId=39. How t

相关标签:
1条回答
  • 2021-01-05 22:26

    Assuming you have a numerical id followed by an i and you want the id coming back as just the numerical.

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

    This will match a numeric followed by an i and will give you just the numeric in req.params.id.

    Example:

    curl -XGET localhost:8080/124i
    

    Gives me the following in req.params

    [ 'id': 124 ]
    
    0 讨论(0)
提交回复
热议问题