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. Http中的同步请求和异步请求

    最近在上springmvc的JSON数据交换的时候,老师下课提了一个课后问题:什么是异步请求?什么是同步请求?我想大部分同学听到这个问题的时候应该和我一样不知所云.现在,给大家分享一篇关于同步请求和异 ...

  2. diverta 2019 Programming Contest

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  3. MarkdownPad2安装与破解-转载

    MarkdownPad安装包下载链接链接:https://pan.baidu.com/s/1o7c4W7C2d8zCPh5z7y4IvQ提取码:e4bf 下载解压之后,找要MarkdownPad2.e ...

  4. (六)maven之常用插件

    一.maven的插件 maven官方插件:http://maven.apache.org/plugins/index.html 二.常用插件之:javadoc 作用:生成代码文档 2.1 编写代码,并 ...

  5. springboot中使用验证码kaptcha

    1.pom.xml引入kaptcha所需要的jar包 <!-- 验证码 --> <dependency> <groupId>com.github.penggle&l ...

  6. Deep Learning方向的paper

    转载 http://hi.baidu.com/chb_seaok/item/6307c0d0363170e73cc2cb65 个人阅读的Deep Learning方向的paper整理,分了几部分吧,但 ...

  7. es6中Array.from()

    Array.from()方法就是将一个类数组对象或者可遍历对象转换成一个真正的数组. 那么什么是类数组对象呢?所谓类数组对象,最基本的要求就是具有length属性的对象. 1.将类数组对象转换为真正数 ...

  8. Ubuntu安装rpm

    # sudo apt-get install alien # sudo alien xxx.rpm # sudo dpkg -i xxx.deb

  9. 你不知道的javascript(上卷)读后感(二)

    this词法 熟悉ES6语法的开发者,箭头函数在涉及this绑定时的行为和普通函数的行为完全不一致.跟普通this绑定规则不一样,它使用了当前的词法作用域覆盖了this本来的值. 误解 this理解成 ...

  10. RabbitMQ中初始化ConnectionFactory常用设置属性

    初始化ConnectionFactory 代码 ConnectionFactory factory = new ConnectionFactory(); factory.setHost(ip); fa ...