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-dynamodb-session

v1.1.0

Published

Connect session store for AWS DynamoDB

Downloads

13

Readme

connect-dynamodb-session

DynamoDB session store for Connect and Express

Circle CI npm npm Dependency Status devDependency Status

Usage

Express or Connect integration

const session = require('express-session');
const DynamoStore = require('connect-dynamodb-session')(session);

app.use(session({
  secret: 'foo',
  store: new DynamoStore({
    region: 'us-west-2',
    tableName: 'mySessionTable',
    cleanupInterval: 100000,
    touchAfter: 0
  })
}));

Create the table (optional - alternatively use the autoCreate option, see below)

For example using the aws cli:

aws \
    --region us-west-2 \
    dynamodb create-table \
    --table-name ${YOUR_TABLE_NAME} \
    --attribute-definitions AttributeName=id,AttributeType=S \
    --key-schema AttributeName=id,KeyType=HASH \
    --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5

Be sure to read the aws documentation about ReadCapacityUnits and WriteCapacityUnits before deploying to production.

Options

  • client (optional) provide your own client that exposes init, get, put, delete, setExpires & deleteExpired, see src/dynamo.js for an implementation.
  • ttl (optional, default: 1209600000 (two weeks)) expiration time of session in milliseconds. Fall back to use if the cookie does not have an expires value. Normally you set the expires value for the cookie:
app.use(session({
  cookie: {maxAge: 1209600000},
  secret: 'foo',
  store: new DynamoStore(options)
}));
  • cleanupInterval (optional, default: 300000 (five minutes)) how often to wait in-between scans of the the table to remove expired sessions. Set to 0 to never remove expired sessions.
  • touchAfter (optional, default: 10000 (ten seconds)) if the session hasn't changed, then don't persist it to dynamo more than once every 10 seconds. Set to 0 to always update dynamo WARNING setting to 0 can seriously impact your WriteCapacityUnits. Inspired by connect-mongo. Requires the resave session option to be false:
app.use(session({
  secret: 'foo',
  resave: false, //don't save session if unmodified
  store: new DynamoStore({
    region: 'us-west-2',
    tableName: 'mySessionTable',
  })
}));
  • err (optional, default: () => {}) error logging, called with (message, error).
  • log (optional, default: () => {}) debug logging, called with (message).

AWS Options

  • region (required unless awsClient set) aws region to use.
  • tableName (required) name of the dynamodb table to use.
  • endpoint (optional) override the aws endpoint, for example to use a local dynamodb for development.
  • awsClient (optional) override the aws dynamo db client, for testing or to use a pre-configured client.
  • autoCreate (optional, default: false) if the table does not exist in aws, then attempt to create it on init
  • readCapacity (optional, default: 5) if autoCreate is true, and the table does not exist, then this setting is used to create the table NOTE this setting does not edit the capacity of a table that already exists.
  • writeCapacity (optional, default: 5) if autoCreate is true, and the table does not exist, then this setting is used to create the table NOTE this setting does not edit the capacity of a table that already exists.
  • consistentRead (optional, default: true) if this is set to false, then getting sessions is down with weak consistency which will reduce your reqired ReadCapacityUnits, but may cause issues, especially if you have multiple instances of your node server connecting to the same table.

Tests

Docker and docker-compose are required to run tests, since we are using local DynamoDB image for End-to-end testing

yarn lint
yarn test

License

The MIT License