Skip to content

Instantly share code, notes, and snippets.

@ipiyer
Created February 7, 2016 03:18
Show Gist options
  • Save ipiyer/30934e4827b6d10fa627 to your computer and use it in GitHub Desktop.
Save ipiyer/30934e4827b6d10fa627 to your computer and use it in GitHub Desktop.
Express + postgres + knex + bookshelf example
const session = require('express-session'),
pg = require("pg"),
pgSession = require('connect-pg-simple')(session);
const pgConnection = {
host: 'localhost',
user: 'blahblah',
database: 'foobar',
charset: 'utf8'
}
const knex = require('knex')({
client: 'pg',
connection: pgConnection,
debug: true
}),
bookshelf = require('bookshelf')(knex);
// middleware
app.use(session({
store: new pgSession({
pg: pg,
conString: pgConnection,
tableName: 'session'
}),
resave: false,
saveUninitialized: true,
secret: "i am a secret",
cookie: {
maxAge: 1 * 365 * 24 * 60 * 60 * 1000 // 1 years;
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment