Created
February 27, 2012 17:16
-
-
Save clonn/1925595 to your computer and use it in GitHub Desktop.
Express middleware simple example for node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @overview | |
* | |
* @author Caesar Chi | |
* @blog clonn.blogspot.com | |
* @version 2012/02/27 | |
*/ | |
var express = require('express'), | |
app = express.createServer(), | |
port = 1337; | |
function middleHandler(req, res, next) { | |
console.log("execute middle ware"); | |
next(); | |
} | |
app.use(function (req, res, next) { | |
console.log("first middle ware"); | |
next(); | |
}); | |
app.use(function (req, res, next) { | |
console.log("second middle ware"); | |
next(); | |
}); | |
app.get('/', middleHandler, function (req, res) { | |
console.log("end middleware function"); | |
res.send("page render finished"); | |
}); | |
app.listen(port); | |
console.log('start server'); |
what would be the output when following runs on root route??
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Thank you for the info, I was looking a way to execute the middleware, not just declare it.