标签:
先看一段测试代码:
1 var express = require(‘express‘); 2 3 var app = express(); 4 var router = express.Router(); 5 6 app.get(‘/‘, function(req, res){ 7 console.log(‘test1‘); 8 }); 9 10 app.use(‘/‘, function(req, res){ 11 console.log(‘test2‘); 12 }); 13 14 router.get(‘/‘, function(req, res){ 15 console.log(‘test3‘); 16 }); 17 18 app.listen(4000);
输入url: localhost:4000
1 app.use([path], [function...], function) 2 Mount the middleware function(s) at the path. If path is not specified, it defaults to "/". 3 4 Mounting a middleware at a path will cause the middleware function to be executed whenever the base of the requested path matches the path.
标签:
原文地址:http://www.cnblogs.com/chenchenluo/p/4192282.html