![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
express-mongoose-store
Advanced tools
Session store for people who want to use MongoDB sessions, and already have a MongooseJS connection for their backend.
##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.
###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.4 - Bug fix
#####v1.0.3 - Session expiration with MongoDB expires via @rubenstolk
#####v1.0.2 - Configurable Model Name for Session via @rubenstolk
FAQs
Session store for people who want to use MongoDB sessions, and already have a MongooseJS connection for their backend.
The npm package express-mongoose-store receives a total of 15 weekly downloads. As such, express-mongoose-store popularity was classified as not popular.
We found that express-mongoose-store demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.