• learning express step(六)


    code: use application middleware

    var express =  require('express');
    var app = express();
    
    app.use(function (req, res, next) {
        console.log('Time', Date.now());
        next()
    });
    
    app.use('/user/:id', function (req, res, next) {
        console.log('Request Type:', req.method);
        next();
    },function (req, res, next) {
        console.log('Request URL', req.originalUrl);
        next();
    });
    
    app.get('/user/:id', function(req, res){
        res.send("USER");
    });
    app.listen(3000);

    result:

    C:UsersadminWebstormProjectslearning-express-step6>node learning-express-step6.js
    Time 1560331355675
    Request Type: GET
    Request URL /user/id=123
    Time 1560331371325
    Request Type: GET
    Request URL /user/id=123

    web result:  pass id field

  • 相关阅读:
    Alpha冲刺Day5
    Alpha冲刺Day4
    Alpha冲刺Day3
    团队作业——随堂小测
    Alpha冲刺Day2
    Alpha冲刺Day1
    团队项目需求分析
    结对项目第二次作业
    Linux中exec命令相关
    .lib和.dll文件
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11010989.html
Copyright © 2020-2023  润新知