New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

better-express-store

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-express-store

A session store for express-session using the db driver better-sqlite3

1.0.5
latest
Source
npm
Version published
Maintainers
0
Created
Source

better-express-store

A session store for express-session using the db driver better-sqlite3

What does this module do?

Express-session uses the internal memory as its default store for sessions. This is not recommended in a production environment.

If you use SQLite as your database and better-sqlite3 as your database driver then this module easily lets you store your sesions in the db.

Installation

You need to have installed express, express-session and better-sqlite3 first:

npm i express
npm i express-session
npm i better-sqlite3

Then you install better-express-store:

npm i better-express-store

Usage

This is an example of how you use this module:

const express = require('express');
const session = require('express-session');
const store = require('better-express-store');

const app = express();

// When setting up express session
app.use(session({
  secret: 'your own secret',
  resave: false,
  saveUninitialized: true,
  cookie: { secure: 'auto' },
  // change dbPath to the path to your database file
  store: store({  dbPath: './db/my-db.db'})
}));

// Set up other middleware and start your server...

Defaults

Apart from your dbPath there are also other settings you can adjust.

The settings (listed together with their default values):

{
  dbPath: false, // no default - needs to specified
  tableName: 'sessions',
  deleteAfterInactivityMinutes: 120, // 0 = never delete
}

Keywords

express-session

FAQs

Package last updated on 05 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts