1.引入模块
首先在命令行工具中安装express ==> npm install express -s
const express = require('express');
2.初始化express
let app = express();
3.调用中间件
app.use(function(req,res,next)={
if(login){
next();
}
})
app.get('/login',(req,res)=>{
console.log(req.path);
})
4.启动监听
app.listen(1234,(err)=>{
if(err) return console.log('error');
console.log('server running');
})
网友评论