How to use morgan with node-simple-router

Published on

You can use it like a middleware as it is supposed to be used in combination with router.any to log any reqeust of the web server.

Here a simple example:

var http = require('http')
  , router = require('node-simple-router')()
  , morgan = require('morgan')
  , logger = morgan('combined')

router.any(function(){
  logger.apply(this,arguments)
})

router.get('/hook',function(req, res) {
  res.end('incoming hook')
})


http
.createServer(router)
.listen(3000)

Here, have a slice of pizza 🍕