Skip to content

Instantly share code, notes, and snippets.

@clonn
Created February 27, 2012 17:16
Show Gist options
  • Save clonn/1925595 to your computer and use it in GitHub Desktop.
Save clonn/1925595 to your computer and use it in GitHub Desktop.
Express middleware simple example for node.js
/**
* @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');
@Vyomrana02
Copy link

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