Skip to content

Instantly share code, notes, and snippets.

@jkantr
Last active July 6, 2017 04:05
Show Gist options
  • Save jkantr/fc4c0ec5316f88a02f992788c3ab2b25 to your computer and use it in GitHub Desktop.
Save jkantr/fc4c0ec5316f88a02f992788c3ab2b25 to your computer and use it in GitHub Desktop.
Mounted Routers as Parametric Modules
const express = require('express')
const router = express.Router()
module.exports = (Knex) => {
router.get('/', (req, res) => {
// now you have Knex object in scope!
res.render('main', { title: 'Main' })
})
return router
}
const Knex = "Pretend this is your knex object"
const api = require('./routes/api.js')(Knex)
app.use('/api', api)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment