A simple, minimal PostgreSQL session store for Express/Connect
npm install connect-pg-simple
Once npm installed the module, you need to create the session table in your database. For that you can use the [table.sql] (https://github.com/voxpelli/node-connect-pg-simple/blob/master/table.sql) file provided with the module:
psql mydatabase < node_modules/connect-pg-simple/table.sql
Or simply play the file via a GUI, like the pgAdminIII queries tool.
Examples are based on Express 4.
var session = ;app;
Advanced example showing some custom options:
var pg =session =pgSession = session;app;
Express 3 (and similar for Connect):
var express = ;app;
DATABASE_URLenvironment variable (as you do by default on eg. Heroku) – then you need to specify the connection string or object here so that this module that create new connections. Needen even if you supply your own database module.
session, then you can specify that here.
60seconds. If set to
falseno automatic pruning will happen. Automatic pruning weill happen
pruneSessionIntervalseconds after the last pruning – manual or automatic.
console.error(), but can be useful to override if one eg. uses Bunyan for logging.
3.0.0, then the timers will block any graceful shutdown unless you tell the automatic pruning to stop by closing the session handler using this method.
false– which can be useful if one wants improved control of the pruning.