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}`)
})

 

posted on 2020-11-27 10:21  秃了头也不退休  阅读(261)  评论(0编辑  收藏  举报

导航