THIS REPOSITORY AND PACKAGE WILL BE DEPRECATED IN JULY 2024
Google Cloud Datastore Sessions

@google-cloud/connect-datastore is a Google Cloud Datastore
session store backed by @google-cloud/datastore.
Note: Cloud Datastore is a persistent, distributed, transactional database.
Often, it's more appropriate to choose a different storage solution for sessions
such as Memcache or Redis as their designs offer much faster operation in this
use case.
Installation
npm install @google-cloud/connect-datastore
Configuration
You must have a Google Cloud project and credentials.
See gcloud node's documentation on setting up authentication.
Usage Example
const {Datastore} = require('@google-cloud/datastore');
const {DatastoreStore} = require('@google-cloud/connect-datastore');
const express = require('express');
const session = require('express-session');
const app = express();
app.use(session({
store: new DatastoreStore({
kind: 'express-sessions',
expirationMs: 0,
dataset: new Datastore({
projectId: process.env.GCLOUD_PROJECT,
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS
})
}),
secret: 'my-secret'
}));
Expiration
If a session is fetched with the delta between the createdAt time and current
time greater than expirationMs, the session will not be returned and will
instead be destroyed.
Datastore does not support a ttl
, and tokens are only deleted if a session
is fetched. You will likely want to implement logic to occasionally delete
expired sessions.
Contributing
License