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

nedb-session-store

v1.1.2

Published

A session store implementation for Connect & Express backed by an NeDB datastore (either in-memory or file-persisted)

Downloads

785

Readme

nedb-session-store

GitHub Latest Release Build Status Dependency Status Dev Dependency Status

A session store implementation for Express & Connect backed by an NeDB datastore (either in-memory or file-persisted).

Compatibility

Supports integration with:

Getting Started

npm install --save nedb-session-store

Usage

// ...set up a Connect-compatible session/app...

var NedbStore = require('nedb-session-store')( connectCompatibleSession );

var store = new NedbStore({
  filename: 'path_to_nedb_persistence_file.db'
});

For further details on how to integrate this module with various Connect-compatible middleware environments (e.g. Express), see Middleware Integration

Options

defaultExpiry

Optional. [Date] The default expiry period (max age) in milliseconds to use if and ONLY if the session's expiration is not controlled by the session Cookie configuration. Defaults to 2 weeks.

inMemoryOnly

Optional. [Boolean] Only persist the datastore within the available in-process memory. Defaults to false.

filename

Optional. [String] The path to the file where the datastore will be persisted. If not provided, the datastore will automatically be assigned the filename of 'data/sessions.db'.

For more details about the underlying filename option, please read about it in the NeDB documentation.

afterSerialization

Optional. [Function] A hook that you can use to transform data after it was serialized and before it is written to disk. A common example usage for this hook is to encrypt data before writing the database to disk.

ONLY applies when your NeDB datastore is file-persisted!

For more details about the underlying afterSerialization option, please read about it in the NeDB documentation.

beforeDeserialization

Optional. [Function] The inverse of afterSerialization: a hook that you can use to transform data after it was read from disk and before it is deserialized. A common example usage for this hook is to decrypt data after reading the database from disk.

ONLY applies when your NeDB datastore is file-persisted!

For more details about the underlying beforeDeserialization option, please read about it in the NeDB documentation.

corruptAlertThreshold

Optional. [Number] NeDB will refuse to start if more than this percentage of the datafile is corrupt. Valid values must be a number between 0 (0%) and 1 (100%). A value of 0 means you do NOT tolerate any corruption, 1 means you do not care about corruption. NeDB uses a default value of 0.1 (10%).

ONLY applies when your NeDB datastore is file-persisted!

For more details about the underlying corruptAlertThreshold option, please read about it in the NeDB documentation.

autoCompactInterval

Optional. [Number] NeDB's file persistence uses an append-only format for performance reasons, meaning that all updates and deletes actual result in lines being added at the end of the datastore file. To compact the file back into a 1-line-per-document format, you must either restart your application or specify an automatic compaction interval with this option. Valid values must be either null (disabled) or an integer between 5000 (5 seconds) and 86400000 (1 day). Defaults to 1 day.

ONLY applies when your NeDB datastore is file-persisted!

For more details about the underlying automatic compaction functionality, please read about it in the NeDB documentation.

Middleware Integration

Express

[email protected]

[email protected]

To integrate with modern versions of Express (4.x and above):

var sharedSecretKey = 'yoursecret';
var express = require('express');
var session = require('express-session');
var app = express();

var NedbStore = require('nedb-session-store')(session);

app.use(
  session({
    secret: sharedSecretKey,
    resave: false,
    saveUninitialized: false,
    cookie: {
      path: '/',
      httpOnly: true,
      maxAge: 365 * 24 * 60 * 60 * 1000   // e.g. 1 year
    },
    store: new NedbStore({
      filename: 'path_to_nedb_persistence_file.db'
    })
  })
);

[email protected]

[email protected]

To integrate with deprecated versions of Express (3.x and 2.x):

var sharedSecretKey = 'yoursecret';
var express = require('express');
var app = express();

var NedbStore = require('nedb-session-store')(express);

app.use(express.cookieParser(sharedSecretKey));
app.use(
  express.session({
    secret: sharedSecretKey,
    resave: false,
    saveUninitialized: false,
    cookie: {
      path: '/',
      httpOnly: true,
      maxAge: 365 * 24 * 60 * 60 * 1000   // e.g. 1 year
    },
    store: new NedbStore({
      filename: 'path_to_nedb_persistence_file.db'
    })
  })
);

Connect

[email protected]

To integrate with modern versions of Connect (3.x and above):

var sharedSecretKey = 'yoursecret';
var connect = require('connect');
var session = require('express-session');
var app = connect();

var NedbStore = require('nedb-session-store')(session);

app.use(
  session({
    secret: sharedSecretKey,
    resave: false,
    saveUninitialized: false,
    cookie: {
      path: '/',
      httpOnly: true,
      maxAge: 365 * 24 * 60 * 60 * 1000   // e.g. 1 year
    },
    store: new NedbStore({
      filename: 'path_to_nedb_persistence_file.db'
    })
  })
);

[email protected]

[email protected]

To integrate with deprecated versions of Connect (2.x and 1.x (technically >= 1.0.3)):

var sharedSecretKey = 'yoursecret';
var connect = require('connect');
var app = connect();

var NedbStore = require('nedb-session-store')(connect);

app.use(connect.cookieParser(sharedSecretKey));
app.use(
  connect.session({
    secret: sharedSecretKey,
    resave: false
    saveUninitialized: false,
    cookie: {
      path: '/',
      httpOnly: true,
      maxAge: 365 * 24 * 60 * 60 * 1000   // e.g. 1 year
    },
    store: new NedbStore({
      filename: 'path_to_nedb_persistence_file.db'
    })
  })
);

License

Copyright (c) 2015, James M. Greene @ Viavi Solutions, Inc. (MIT License)

This software was developed during the course of my work at Viavi Solutions, Inc. and has been publicly released with their permission.