Coder Social home page Coder Social logo

express-rethinkdb-store's Introduction

express-rethinkdb-store

npm version

A (currently basic) implementation of a RethinkDB Session Store.

It's a complete rewrite based on express-session-rethinkdb.

Usage

Install and save Package with

npm install --save express-rethinkdb-store

then, assuming your express app is in app

const session = require("express-session")
const RethinkStore = require("express-rethinkdb-store")
const store = new RethinkStore()

app.use(session({
	secret: "supersecret",
	cookie: "connect.sid",
	store: store,
	resave: false,
	saveUninitialized: false
}))

Features

  • Completely written in ES6 / ES.next
  • Highly readable (See RethinkStore.js)
  • Data is loaded directly from database, so no stale data in a local cache
    • A cache utilizing RethinkDBs changefeeds is on the roadmap
  • RethinkDB can't natively expire documents, so we remove expired sessions automatically after flushInterval milliseconds (60s by default). When a session gets requested it's expiry is automatically checked and, if expired, the session is removed.

API

Example with default values

new RethinkStore({
	connectionOptions: {},      // See: https://www.rethinkdb.com/api/javascript/#connect
	table: "session",           // Session table
	sessionTimeout: 86400000,   // Session timeout in milliseconds
	flushInterval: 60000        // Interval to delete expired sessions from database
})

Internals

callback_decorator

Used to wrap the modern async/await functions (async functions that return a promise instead of using callbacks).

// ES.next Syntax!
class RethinkStore extends session.Store {
	@callback_decorator
	async destroy(sid) {
		await r.table(this.table).get(sid).delete()
	}
}

After decoration destroy accepts a second parameter cb. This is required because express-session uses callback-style

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.