learning express.Router()

code:

const express = require('express');
const app = express();
var router = express.Router(); var cookieParser = require('cookie-parser'); app.use(cookieParser());
router.use(function (req, res, next) {
//if (!req.headers['x-auth']) return next('router');
//next();
}) router.get('/', function(req, res){
res.send('hello, user!');
}); app.use('/admin', router, function (req, res) {
res.sendStatus();
}); // app.use(function(err, req, res, next){
// console.error(err.stack);
// res.status(500).send('something broke');
// });
app.listen();

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  middleware var express = require('express'); var app = express(); var myLogger = ...

  5. learning express step(四)

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

  6. learning express step(九)

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

  7. learning express step(八)

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

  8. learning express step(七)

    Route handlers enable you to define multiple routes for a path. The example below defines two routes ...

  9. learning express step(六)

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

随机推荐

  1. redis用法分析

    redis基本介绍 redis也是一个内存非关系型数据库,它拥有memcache在数据存储上的全部优点,而且在memcache的基础上增加了数据持久性功能,redis用rdb和aof两种方式实现数据持 ...

  2. Python开发【第四章】:函数剖析

    一.Python函数剖析 1.函数的调用顺序 #!/usr/bin/env python # -*- coding:utf-8 -*- #-Author-Lian #函数错误的调用方式 def fun ...

  3. Struts2连接Mysql的Crud使用

    今天分享的是struts2框架中增删改查的用法: 一:利用Struts2框架 1.1在pom.xml中导入相关依赖 <project xmlns="http://maven.apach ...

  4. Java锁的升级策略 偏向锁 轻量级锁 重量级锁

    这三种锁是指锁的状态,并且是专门针对Synchronized关键字.JDK 1.6 为了减少"重量级锁"的性能消耗,引入了"偏向锁"和"轻量级锁&qu ...

  5. (九)springmvc之json的处理(服务端发送json数据到客户端)

    一.json处理方法有两种 1:导入Spring需要json的jar包.(本例使用) 使用@ResponseBody该注解用于将Controller的方法返回的对象,通过HttpMessageConv ...

  6. 学习C#自作计算器,菜鸟初学,有大神的指点,希望做的不够好的地方请大家多多指导。同时希望非常无聊的大神能加些其它计算进去

    可以做幂运算,根号运算,十进制与二进制互转,16进制与十进制互转 namespace WindowsFormsApplication15 { public partial class 祥哥计算器 : ...

  7. java 框架-分布式文件管理系统1FastDFS

    https://www.cnblogs.com/chiangchou/p/fastdfs.html

  8. HashSet和CopyOnWriteArraySet(转载)

    前言 这篇文章的目的如下: HashSet是如何保证元素的不重复和无序 HashSet的增删(改查?)原理 CopyOnWriteArraySet支持并发的原理 CopyOnWriteArraySet ...

  9. optparser模块 与 ZIP爆破(Python)

    optparser模块: 为脚本传递命令参数. 初始化: 带 Usage 选项(-h 的显示内容 Usage:): >>> from optparse import OptionPa ...

  10. springboot启动流程(三)Environment简介

    所有文章 https://www.cnblogs.com/lay2017/p/11478237.html 简介 上一篇文章中,我们简单了解了一下SpringApplication的run方法的代码逻辑 ...