express-中间件

let express=require('express')


let app=express()

app.use(express.static('public'))


app.use(function(req,res,next){ //这就是中间件 执行next后 往下继续执行
  console.log('first middleware')
  next()
})



app.get('/',function(req,res,next){
  res.send('ok')
})


app.listen(4321,()=>console.log('app has running in port 4321'))
原文地址:https://www.cnblogs.com/lxz-blogs/p/14047922.html