Created
April 8, 2015 04:33
-
-
Save greggnakamura/2bf83e37b201797ddc50 to your computer and use it in GitHub Desktop.
Express: Middleware and Request Flow
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
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); |
Author
greggnakamura
commented
Apr 8, 2015
- Connect Middleware
- More Connect Middleware
- Express Middleware
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment