ssess
Simple session middleware
Now less of an incoherent mess! Call today!
Install npm install ssess
Example
var ssess = ;var manager = ; // Create a session manager middlewareStack; // Use in your middleware stack { var userSession = manager; // Pass res to allow cookie setting userSession;} { var user = reqsession; // Display something using the user data reqsession; // Set some other data for this session} { reqsession; // Needs res to delete cookies}
API
ssess([options])
ttl: 500 // Seconds to keep session alive without a refresh, defaults to 2 weeks name: 'deadbeef' // The cookie name to use for keeping track of sessions, defaults to 'sid' auto: true // If true, automatically create a session for every visitor, defaults to false
- Returns a new session manager, shown below
manager.create(res[, options])
res
is the response object, used to send the cookie to the clientoptions
is like the options object above, but only supports customttl
for individual sessions- Returns an individual visitor session, shown below
session
-
get(key)
-
set(key, value[, expire])
- Has an alias,
put
expire
is in seconds
- Has an alias,
-
del(key)
-
clear()
- Clears all data and expiration timers from the session
- See thecache documentation for more details on
get
/set
/del
/clear
-
destroy(res)
- Need
res
to kill the cookie on the client - Delete contents of session and remove itself from the manager
- Need
-
id
- Just in case the session is passed to something that needs to know it's id
- This is the value of the cookie sent to the client, and the key used to lookup this session in the manager
Note: Adds cookies
and session
properties to req