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. C# DataTable和List转换操作类

    using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.R ...

  2. Windows 10 下 Linux 子系统的安装和使用

    介绍 适用于 Windows 的 Linux 子系统(英语:Windows Subsystem for Linux,简称 WSL)是一个为在 Windows 10 和 Windows Server 2 ...

  3. Swagger 实践 <二>

    1. 新建.netCore WebApi 项目(选择Angular).按照上一篇的加上Swage 文档,使http://localhost:11934/swagger/v1/swagger.json  ...

  4. 【原创】大叔经验分享(89)docker启动openjdk执行jmap报错

    docker启动openjdk后,可以查看进程 # docker exec -it XXX jps 10 XXX.jar 可见启动的java进程id一直为10,然后可以执行jvm命令,比如 # doc ...

  5. [转载]Java中继承、装饰者模式和代理模式的区别

    [转载]Java中继承.装饰者模式和代理模式的区别 这是我在学Java Web时穿插学习Java设计模式的笔记 我就不转载原文了,直接指路好了: 装饰者模式和继承的区别: https://blog.c ...

  6. VBA术语(三)

    在本章中,将介绍常用的Excel VBA术语.这些术语将在很多的模块中使用,因此理解其中的每一个术语都很重要. 模块 模块是编写代码的区域.如下图中,这是一个新的工作簿,因此没有任何模块. 要插入模块 ...

  7. 关于一个mvc架构的cms的后台getshell

    都知道,mvc的话 除了根目录还有public目录可以访问,其他的访问都是不行的,因为会默认都是会解析url 然后我们来看今天的猪脚 大概的图片上传还有远程文件加载我黑盒测过了  就是想捞一个快一点的 ...

  8. ASE19团队项目 beta阶段 model组 scrum report list

    scrum 1 scrum 2 scrum 3 scrum 4 scrum 5 scrum 6 scrum 7

  9. Microsoft 中间语言

  10. xtrabackup数据库备份工具

    下来我来介绍一下更强大的备份工具:xtrabackup xtrabackup是Percona公司CTO Vadim参与开发的一款基于InnoDB的在线热备工具,具有开源,免费,支持在线热备,备份恢复速 ...