npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connect-deta-base

v0.7.0

Published

Deta Base session store for express-session

Downloads

3

Readme

Unit test Coverage Status

connect-deta-base provides Deta Base session storage for Express.

TypeScript is supported limitedly.

Installation

npm install express deta express-session connect-deta-base

To develop with TypeScript, install below too.

npm install --save-dev @types/express @types/express-session

API

For initialize Deta Base, see also Deta Base official docs.

Ref: https://docs.deta.sh/docs/base/sdk#instantiating

Use JavaScript

const express = require("express");
const session = require("express-session");
const DetaBaseStore = require("connect-deta-base")(session);

const { Deta } = require("deta");
const deta = Deta("project key");
const detaBaseClient = deta.Base("sessions");

const app = express();

app.use(
  session({
    store: new DetaBaseStore({ client: detaBaseClient }),
    saveUninitialized: false,
    secret: "keyboard cat",
    resave: false,
  })
);

Use TypeScript

import express from "express";
import session from "express-session";
import DetaBaseStore from "connect-deta-base";

import { Deta } from "deta";
const deta = Deta("project key");
const detaBaseClient = deta.Base("sessions");

const detaBaseStore = DetaBaseStore(session);

const app = express();

app.use(
  session({
    store: new detaBaseStore({ client: detaBaseClient }),
    saveUninitialized: false,
    secret: "keyboard cat",
    resave: false,
  })
);

DetaBaseStore(options)

The DetaBaseStore requires a Deta Base client.

Options

client

An instance of Deta Base client (required).

prefix

Key prefix in Deta Base (default: sess:).

Note: You may need unique prefixes for different applications sharing the same database. This limits bulk commands exposed in express-session (like length, all, keys, and clear) to a single application's data.

ttl

If the session cookie has a expires date, connect-deta-base will use it as the TTL.

Otherwise, the session will expire using the ttl option (default: 86400 seconds or one day).

Note: The TTL is reset every time a user interacts with the server. You can sometimes disable this behavior by setting false to enableTouch.

enableTouch

Enables re-saving and resetting the TTL when using touch (default: true).

The express-session package uses touch to signal to the store that the user has interacted with the session but hasn't changed anything in its data. Typically, this helps keep the users' session alive if session changes are infrequent but you may want to disable it to cut down the extra calls or to prevent users from keeping sessions open too long. Also, consider disabling if you store a lot of data on the session.

Ref: https://github.com/expressjs/session#storetouchsid-session-callback

enableTTL

Enables key expiration (default: true).

This option enables key expiration requiring the user to manually manage key cleanup outside of connect-deta-base. Only set false if you know what you are doing and have an exceptional case where you need to manage your own expiration in Deta Base.

Note: This has no effect on express-session setting cookie expiration.

Limited support for TypeScript

These methods are not supported yet. Only JavaScript.

  • all
  • clear
  • destroy
  • get
  • set
  • length
  • touch