req.query and req.param in ExpressJS

后端 未结 4 2237
花落未央
花落未央 2020-11-28 04:01

Main differences between req.query and req.param in Express

  • How are Both different from each other
  • When to use then in wha
4条回答
  •  自闭症患者
    2020-11-28 04:24

    I would suggest using following

    req.param('')
    

    req.param("") works as following

    Lookup is performed in the following order:

    req.params
    req.body
    req.query
    

    Direct access to req.body, req.params, and req.query should be favoured for clarity - unless you truly accept input from each object.

    Ref:http://expressjs.com/4x/api.html#req.param

提交回复
热议问题