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();

result:

C:\Users\admin\WebstormProjects\learning-express-step7>node  learning-express-step7.js
ID: id=
ID: id=

web result:

learning express step(七)的更多相关文章

  1. learning express step(十四)

    learning express error handle code: const express = require('express'); const app = express(); const ...

  2. learning express step(十三)

    learning express error handle code: const express = require('express'); const app = express(); app.g ...

  3. learning express step(十二)

    learning express view engine function const express = require('express'); const app = express(); app ...

  4. learning express step(十一)

    learning express.Router() code: const express = require('express'); const app = express(); var route ...

  5. learning express step(五)

    learning  express  middleware var express = require('express'); var app = express(); var myLogger = ...

  6. learning express step(四)

    learning express route function const express = require('express'); const app = express(); app.get(' ...

  7. learning express step(九)

    router-level middleware works in the same way as application-level middleware, except it is bound to ...

  8. learning express step(八)

    To skip the rest of the middleware functions from a router middleware stack, call next('route') to p ...

  9. learning express step(六)

    code: use application middleware var express = require('express'); var app = express(); app.use(func ...

随机推荐

  1. json字符串,json对象,java对象互相转换

    1.把JSON字符串转换为JAVA 对象 JSONObject jsonobject = JSONObject.fromObject(jsonStr); User user= (User)JSONOb ...

  2. scratch少儿编程第一季——01、初识图形化界面编程的神器

    各位小伙伴大家好: 说到2018年互联教育的热门事件,那就不得不提Scratch. 相信各位不关注信息技术领域的各位家长也都听说过这个东西. 对于小学阶段想要接触编程或信息技术学生来说,Scratch ...

  3. Task执行多次

    项目中,曾经出现过启动时数据库连接数瞬间增大,当时并没有注意该问题. 后期,由于Task任务多次执行,才着手查看这个问题,经排查,由于tomcat中webapp配置多次,导致webapp被扫描多次(配 ...

  4. VS2017清除工具、用于清除Microsoft Visual Studio最近打开项目

    最近每天在用VS2017,但是每次打开它都会弹出最近项目的记录,很是烦人. 最主要是我不想别人得知我最近的项目和项目进度,每次加密项目会比较麻烦. 所以经过简单的研究,编写了这个小工具,打开直接单击就 ...

  5. linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现

    linux, kill掉占用60%多cpu的进程,几秒后换个pid 和 command 又出现?快速清理木马流程.假设木马的名字是xysbqaxjqy,如果top看不到,可以在/etc/init.d目 ...

  6. Oracle复习

    这阵子忙着面试 ,之前搞项目一直用的 mysql ,然后面试的大公司!(呵呵)偏偏用的是 oracle 没办法恶补 前面学过的但是没怎么用的Oracle 基础知识,打算主要从下面几点入手. 环境搭建: ...

  7. # marshalsec使用

    开启rmi服务,恶意类放到服务上 D:\jdk_1.8\bin\java.exe -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.RMIRe ...

  8. Ubuntu安装cmake 3.9

    wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz # 下载 cd cmake-3.9.2 ./configure sudo make & ...

  9. PAT Basic 1088 三人行 (20 分)

    子曰:“三人行,必有我师焉.择其善者而从之,其不善者而改之.” 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整数:把甲的能力值的 2 个数字调换位置就是乙的能力值:甲乙两人能力差 ...

  10. cookies, session, token

    Cookie 是由客户端(通常是浏览器)保存的小型文本信息,其内容是一系列的键值对,是由 HTTP 服务器设置并保存在浏览器上的信息. 在post请求的瞬间,cookie会被浏览器自动添加到请求头中. ...