//1.导入express
const express = require('express')
//2.创建web服务器
const app = express()
//利用use()函数定义全局中间件函数
app.use((req,res,next)=>{
//可以为req,res定义自定义的属性或方法来为下游的路由或中间件使用,因为在中间件和路由中res,req值是一致的
const timers = Date()
//定义一个自定义属性为下面的路由使用
res.status = timers
console.log('这是第一个中间件');
//必须调用next()函数,转交给下一个下一个中间件或路由
next()
})
//监听客户端的get请求,使用res.send向客户端发送一些内容
app.get('/',(req,res)=>{
res.send('success' + res.status);
})
//3.启动web服务器
app.listen(80,()=>{
console.log('server is running at http://127.0.0.1');
})