Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Created April 8, 2015 04:33
Show Gist options
  • Save greggnakamura/2bf83e37b201797ddc50 to your computer and use it in GitHub Desktop.
Save greggnakamura/2bf83e37b201797ddc50 to your computer and use it in GitHub Desktop.
Express: Middleware and Request Flow
var express = require('express'),
bodyParser = require('body-parser'),
app = express();
// third party middleware
app.use(bodyParser.urlencoded());
// custom middleware
app.use(function (req, res, next) {
console.log('this will log on every request');
next();
});
// route function (get, post, put, delete)
app.get('/', log, function (req, res) {
res.render('index.jade', { names: names });
});
// built-in middleware; static files (i.e. - css, images, all other static files)
app.use(express.static('./public'))
app.listen(3000);
@greggnakamura
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment