1、express 中间件使用
/*
* 中间件:就是匹配路由之前和匹配路由之后做的一系列操作
*/ var express = require('express');
var app = new express(); /**
* 内置中间件:托管静态页面
*/
//http://localhost:8001/news
app.use(express.static('public')); //虚拟目录 http://localhost:8001/static/news
app.use('/static',express.static('public'));

 //ejs中 设置全局数据 所有的页面都可以使用
  app.locals['userinfo']='1213';

/**
* 中间件:表示匹配任何路由
* 应用级中间件
* next() 路由继续向下匹配
*/
app.use(function (req,res,next) {
console.log(new Date());
next();
}) app.get('/',function (req,res) {
res.send("hello express");
}) app.get('/news',function (req,res,next) {
//res.send("hello news");
console.log("news");
next();
}) app.get('/news',function (req,res) {
res.send("hello news1");
}) app.listen("");

最新文章

  1. AngularJS中的JSONP实践
  2. centos7查看端口命令
  3. Sprite Editor 图集切片精灵
  4. App开发者必备的运营、原型、UI设计工具整理
  5. maven auto-config 多环境自动打包
  6. jquery 中$.post获取MVC Controller中JsonResult返回包含LIst<Model>类型的子List<Model>的高级使用方法
  7. Dragger代码实现
  8. css6种隐藏元素的方法
  9. /etc/profile /etc/bashrc ~/.bash_profile ~/.bashrc ~/.bash_logout 说明及区别
  10. a标签传递参数
  11. 在模态框(Modal)中使用UEditor全屏显示的一个坑
  12. Robotics Tools
  13. 51nod 1636 教育改革
  14. The role of the inter-controller consensus in the placement of distributed SDN controllers
  15. SWD and JTAG selection mechanism
  16. tensor flow 安装
  17. [HNOI2008]玩具装箱
  18. 基于PCIe的高速接口设计
  19. Dalvik与JVM区别
  20. STM32之中断

热门文章

  1. zabbix分布式部署和主机自动发现
  2. Redis位操作介绍
  3. VSCode配合chrome浏览器调试cocos2d js项目
  4. Apache提示You don't have permission to access / on this server 解决
  5. Spring EntityResolver ".dtd" 和 ".xsd"检验
  6. SELinux 对nginx访问目录的影响
  7. thinkPHP5.0.22初体验---request相关用法
  8. Python 文件I/OⅡ
  9. element-ui 弹出添加拖拽功能
  10. Trie树(字典树)整理