-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple.js
44 lines (36 loc) · 1017 Bytes
/
simple.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var express = require('express');
var emt = require('../'); // require('express-middleware-timer');
var app = express();
/***
* Initialize express-timer-middleware
***************************************************/
app.use(emt.init());
/***
* time slow middleware
* - non-anon middleware don't require names
***************************************************/
function slowMiddleware(req, res, next) {
setTimeout(function() {
next();
}, 200);
}
app.use(emt.instrument(slowMiddleware));
/***
* time fast middleware
* - anon middleware require names
***************************************************/
var fastMiddleware = function(req, res, next) {
next();
};
app.use(emt.instrument(fastMiddleware, 'fastMiddleware'));
/***
* Route
***************************************************/
app.get('/', function(req,res) {
res.send('hello world');
});
/***
* Start
***************************************************/
app.listen(3000);
console.log('Listening on port 3000');