• learning express step(七)


    Route handlers enable you to define multiple routes for a path.

    The example below defines two routes for GET requests to the /user/:id path.

    The second route will not cause any problems, but it will never get called because the first route ends the request-response cycle.

    const express  = require('express');
    const app =  express();
    
    app.get('/user/:id', function (req, res, next) {
        console.log('ID:', req.params.id);
        next();
    },function (req, res, next) {
        res.send('User Info');
    });
    
    app.get('/user/:id',function (req, res, next) {
        console.log(req.params.id);
        res.end(req.params.id);
        //res.send(req.params.id);
    });
    
    app.listen(3000);

    result:

    C:UsersadminWebstormProjectslearning-express-step7>node  learning-express-step7.js
    ID: id=123
    ID: id=123

    web result:

  • 相关阅读:
    CRC在线计算器
    freemodbus-v1.5.0 源码分析
    图及其实现
    最短路径
    交换排序-------快速排序
    FreeRTOS--删除任务
    Install OE and BitBake
    高端编程之DOM
    timeout使用实例
    使用JS提交表单
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/11011133.html
Copyright © 2020-2023  润新知