Gitlab NPM Twitter
Kado
High Quality JavaScript Libraries

Session

Introduced in 4.0.0

Stability: 2 - Stable

const Session = require('kado/lib/Session')

The Session library provides both the means for creating middleware to load save and prune sessions. There is also a SessionStoreMemory for storing sessions locally to memory within a single process. As well as a full suite of SessionStoreLocal and SessionStorage for implementing a client to server relationship for saving and restoring sessions.

Class: Session

static Session.getMiddleware(options)

Available Settings:

static Session.generateId(ip, userAgent, secret)

Internal Use

static Session.request(req, res, options)

Internal Use

Session.constructor(sid, store)

Session.restore()

Session.set(key, value)

Session.get(key)

Session.save()

Class: SessionStorage

This class provides a server that can be used to store sessions made by the SessionStoreLocal instance.

Example Usage

const fs = require('kado/lib/FileSystem')
const Session = require('kado/lib/Session')
const saveFile = fs.path.join(__dirname, '.session.json')
const storage = new Session.SessionStorage({ saveFile: saveFile })
storage.restoreFromDisk()
storage.listen()

static SessionStorage.create(options)

SessionStorage.constructor(options)

Available Settings:

SessionStorage.handleSocket(socket)

Internal Use

SessionStorage.save(sid, data)

Internal Use

SessionStorage.restore(sid)

Internal Use

SessionStorage.saveToDisk()

Internal Use

SessionStorage.restoreFromDisk()

Loads the session file synchronously and sets the session data from it.

Internal Use

SessionStorage.clearInterval()

Stop the storage from saving to disk. Cannot be restarted in this instance.

SessionStorage.listen(port, host)

Class: SessionStore

SessionStore.constructor()

Available Settings:

SessionStore.save(sid, data)

This method must be extended and will error otherwise.

SessionStore.restore(sid)

This method must be extended and will error otherwise

SessionStore.prune()

This method must be extended and will error otherwise. Also, it the storage mechanism must decide on a method for pruning.

Class: SessionStoreLocal

SessionStoreLocal.constructor(options)

Available Settings:

SessionStoreLocal.save(sid, data)

SessionStoreLocal.restore(sid)

SessionStoreLocal.prune()

This method uses the duration and timestamps on the session data to prune the records.

Class: SessionStoreMemory

SessionStoreMemory.constructor(options)

Available Settings:

SessionStoreMemory.save(sid, data)

SessionStoreMemory.restore(sid)

SessionStoreMemory.prune()

This method uses the duration and timestamps on the session data to prune the records.