express-动态路由参数-查询字符串

const express = require('express')

const app = express()


app.get('/api/:id/:name',function(req,res){  //http://localhost:3000/api/333/小明
  console.log(req.params)
  res.send('hello  '+req.params.id)
})

app.get('/apl?cd',function(req,res){ //表示l可以出现一次或0次 http://localhost:3000/apcd
  res.send('apl')
})

app.listen(3000,()=>console.log('app has running on prot 3000'))

查询字符串参数  localhost:3000/api?id=111

app.get('/app',function(req,res){
  console.log(req.query)
  res.send(`hello ${req.query.id}`)
})
原文地址:https://www.cnblogs.com/lxz-blogs/p/14046536.html