express(中间件)

2017-07-27  本文已影响0人  悟空你又瘦了
const express = require('express');
const app = express();
app.use((req, res, next) => {
    console.log(req.url + '访问时间' + Date.now());
    next()
});
app.get('/user', (req, res, next) => {
    console.log('result');
    next();
},(req, res) => {
    console.log("result1");
    res.end("result1");
});
app.listen(3000, ()=>{
    console.log('runing……');
})
const express = require('express');
const app = express();
let cb0 = (req, res, next) => {
    console.log('Cb0');
    next();
};
let cb1 = (req, res, next) => {
    console.log('Cb1');
    next();
};
let cb2 = (req, res) => {
    res.send('Hello Tom');
};
app.get('/user',[cb0, cb1, cb2]);
app.listen(3000, ()=>{
    console.log("running……");
})
const express = require('express');
const app = express();
let count = 0;
app.use((req, res, next) => {
    console.log(req.url + '访问时间' + Date.now());
    next();
});
app.use((req, res, next) => {
    count ++;
    console.log(count);
    next()
});
app.get('/login',(req, res) => {
    res.end('success');
});
app.listen(3000, ()=>{
    console.log("running……");
})
上一篇 下一篇

猜你喜欢

热点阅读