# express-rethinkdb-store

> A session store with rethinkdb backing

Latest version **2.0.0** (published 2018-05-30) · GPLv3 license · 0 weekly downloads

## Install

```sh
npm install express-rethinkdb-store
pnpm add express-rethinkdb-store
yarn add express-rethinkdb-store
bun add express-rethinkdb-store
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-05-30 |
| First published | 2016-06-27 |
| Weekly downloads | 0 |
| License | GPLv3 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 53.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Moritz Mahringer |
| Maintainers | mormahr |

## Links

- npm: https://www.npmjs.com/package/express-rethinkdb-store
- Repository: https://github.com/mormahr/express-rethinkdb-store
- Homepage: https://github.com/mormahr/express-rethinkdb-store#readme
- Issues: https://github.com/mormahr/express-rethinkdb-store/issues
- npm.io page: https://npm.io/package/express-rethinkdb-store

## Dependencies (2)

- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [rethinkdbdash](https://npm.io/package/rethinkdbdash.md) ^2.3.12

## Recent versions

- 2.0.0 (latest) — 2018-05-30
- 1.0.0 — 2016-09-21
- 0.1.0-alpha.4 — 2016-07-05
- 0.1.0-alpha.3 — 2016-06-27
- 0.1.0-alpha.2 — 2016-06-27
- 0.1.0-alpha.1 — 2016-06-27

## README

# express-rethinkdb-store

[![npm version](https://badge.fury.io/js/express-rethinkdb-store.svg)](https://badge.fury.io/js/express-rethinkdb-store)

A (currently basic) implementation of a [RethinkDB](https://www.rethinkdb.com) [Session](https://github.com/expressjs/session) Store.

It's a complete rewrite based on [`express-session-rethinkdb`](https://github.com/armenfilipetyan/express-session-rethinkdb).

## Usage

Install and save Package with
```bash
npm install --save express-rethinkdb-store
```

then, assuming your `express` app is in `app`

```javascript
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](source/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
```javascript
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).

```javascript
// 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

---
_Source: https://npm.io/package/express-rethinkdb-store · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
