Express.js -- Request Object

req.params

Return route param. The stuff before query param -- '?'

  • Node:
router.get('/yomama/:something', function(req, res, next) {
  console.log(req.params.something);
});
  • URI:

http://localhost:3000/fibonacci/yomama/3wafwa?node=xxx

  • Output:

3wafwa

req.query

Return query string object. The stuff after query param -- '?'

  • Node
router.get('/yomama/:something', function(req, res, next) {
  console.log(req.query)
});
  • URI:

http://localhost:3000/fibonacci/yomama/3wafwa?node=xxx

  • Output:

{ node: 'xxx' }

req.path

return everything until '?'

  • URI: http://localhost:3000/fibonacci/yomama/3wafwa?node=xxx
  • Output: /yomama/3wafwa

req.url

return the entire req url

  • URI: http://localhost:3000/fibonacci/yomama/3wafwa?node=xxx
  • Output: /yomama/3wafwa?node=xxx

req.body

return the entire req body

上一篇:Android面试题,android界面开发框架


下一篇:这家餐饮店只用2招,1个月新增200名顾客,方法很简单