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

express-mongoose-store

v1.0.7

Published

Session store for people who want to use MongoDB sessions, and already have a MongooseJS connection for their backend.

Downloads

43

Readme

##Express Mongoose Store express-mongoose is a MongoDB session store backed by MongooseJS. It differs from other MongoDB session stores because it accepts a current Mongoose connection, so you don't have to configure separate connection for your session store if you are already using Mongoose for your backend. It is meant to give a MongoDB session store with minimal config.

###express-mongoose only supports express > 4.0.0

###Installation

$ npm install express-mongoose-store

###Options ttl - how long a session should last from last page view. Defaults to 1 day. cache_ttl - how long a session will be cached in memory

###Usage

var session        = require('express-session');
var mongoose       = require('mongoose');

mongoose.connect();

var MS             = require('express-mongoose-store')(session, mongoose);
app.use(session({ secret: 'keyboard cat', store: new MS({ttl: 600000}) }); //10 minute sessions

###Custom Model Name By default the model name used for storing sessions is "sessions", however, you can customize this by passing a modelName argument to the store like so:

app.use(session({ secret: 'keyboard cat', store: new MS({modelName: 'myApp_sessions' ttl: 600000}) });

Or if you want the session store to keep your Mongoose connection alive as well you can do the following:

var session        = require('express-session');
var mongoose       = require('mongoose');

mongoose.connect();

var MS             = require('express-mongoose-store')(session, mongoose);
var mongoose_store = new MS();

setInterval(function(){
  mongoose_store.keepAlive();
}, 20000);

app.use(session({ secret: 'keyboard cat', store: mongoose_store });

Essentially if your server has a lull in activity this protects your mongoose connection from timing out and having to reconnect, which in express can cause you to throw an error to a user.

###Test Running tests requires a MongoDB instance running on 127.0.0.1:27017 with no authentication. It will also delete anything in a database called "test" in the collection called "sessions" so if that is not desired, you need to modify the tests or not run them.

npm install
npm test

###Change Log

#####v1.0.6 - Add memory caching to limit number of database queries

#####v1.0.5 - Fix for destroy callback

#####v1.0.4 - Bug fix

#####v1.0.3 - Session expiration with MongoDB expires via @rubenstolk

#####v1.0.2 - Configurable Model Name for Session via @rubenstolk