Gathering detailed insights and metrics for @omegion1npm/recusandae-fuga-aliquid
Gathering detailed insights and metrics for @omegion1npm/recusandae-fuga-aliquid
Gathering detailed insights and metrics for @omegion1npm/recusandae-fuga-aliquid
Gathering detailed insights and metrics for @omegion1npm/recusandae-fuga-aliquid
npm install @omegion1npm/recusandae-fuga-aliquid
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3,499 Commits
1 Branches
1 Contributors
Updated on Jul 12, 2025
Latest Version
1.0.0
Package Id
@omegion1npm/recusandae-fuga-aliquid@1.0.0
Unpacked Size
23.04 kB
Size
8.26 kB
File Count
10
NPM Version
10.5.0
Node Version
20.12.2
Published on
Apr 30, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
28
MongoDB-backed session storage for connect and Express. Meant to be a well-maintained and fully-featured replacement for modules like connect-mongo
This module exports a single function which takes an instance of connect
(or Express) and returns a MongoDBStore
class that can be used to
store sessions in MongoDB.
If you pass in an instance of the
express-session
module
the MongoDBStore class will enable you to store your Express sessions
in MongoDB.
The MongoDBStore class has 3 required options:
uri
: a MongoDB connection stringdatabaseName
: the MongoDB database to store sessions incollection
: the MongoDB collection to store sessions inNote: You can pass a callback to the MongoDBStore
constructor,
but this is entirely optional. The Express 3.x example demonstrates
that you can use the MongoDBStore class in a synchronous-like style: the
module will manage the internal connection state for you.
1var express = require('express'); 2var session = require('express-session'); 3var MongoDBStore = require('connect-mongodb-session')(session); 4 5var app = express(); 6var store = new MongoDBStore({ 7 uri: 'mongodb://127.0.0.1:27017/connect_mongodb_session_test', 8 collection: 'mySessions' 9}); 10 11// Catch errors 12store.on('error', function(error) { 13 console.log(error); 14}); 15 16app.use(require('express-session')({ 17 secret: 'This is a secret', 18 cookie: { 19 maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week 20 }, 21 store: store, 22 // Boilerplate options, see: 23 // * https://www.npmjs.com/package/express-session#resave 24 // * https://www.npmjs.com/package/express-session#saveuninitialized 25 resave: true, 26 saveUninitialized: true 27})); 28 29app.get('/', function(req, res) { 30 res.send('Hello ' + JSON.stringify(req.session)); 31}); 32 33server = app.listen(3000);
You should pass a callback to the MongoDBStore
constructor to catch
errors. If you don't pass a callback to the MongoDBStore
constructor,
MongoDBStore
will throw
if it can't connect.
1var express = require('express'); 2var session = require('express-session'); 3var MongoDBStore = require('connect-mongodb-session')(session); 4 5var app = express(); 6var store = new MongoDBStore( 7 { 8 uri: 'mongodb://bad.host:27000/connect_mongodb_session_test?connectTimeoutMS=10', 9 databaseName: 'connect_mongodb_session_test', 10 collection: 'mySessions' 11 }, 12 function(error) { 13 // Should have gotten an error 14 }); 15 16store.on('error', function(error) { 17 // Also get an error here 18}); 19 20app.use(session({ 21 secret: 'This is a secret', 22 cookie: { 23 maxAge: 1000 * 60 * 60 * 24 * 7 // 1 week 24 }, 25 store: store, 26 // Boilerplate options, see: 27 // * https://www.npmjs.com/package/express-session#resave 28 // * https://www.npmjs.com/package/express-session#saveuninitialized 29 resave: true, 30 saveUninitialized: true 31})); 32 33app.get('/', function(req, res) { 34 res.send('Hello ' + JSON.stringify(req.session)); 35}); 36 37server = app.listen(3000);
There are several other options you can pass to new MongoDBStore()
:
1var express = require('express'); 2var session = require('express-session'); 3var MongoDBStore = require('connect-mongodb-session')(session); 4 5var store = new MongoDBStore({ 6 uri: 'mongodb://127.0.0.1:27017/connect_mongodb_session_test', 7 collection: 'mySessions', 8 9 // By default, sessions expire after 2 weeks. The `expires` option lets 10 // you overwrite that by setting the expiration in milliseconds 11 expires: 1000 * 60 * 60 * 24 * 30, // 30 days in milliseconds 12 13 // Lets you set options passed to `MongoClient.connect()`. Useful for 14 // configuring connectivity or working around deprecation warnings. 15 connectionOptions: { 16 serverSelectionTimeoutMS: 10000 17 } 18});
It can support MongoDB instances inside Azure Cosmos. As Cosmos can only support
time-based index on fields called _ts
, you will need to update your configuration.
Unlike in MongoDB, Cosmos starts the timer at the point of document creation so the
expiresAfterSeconds
should have the same value as expires
- as expires
is in
milliseconds, the expiresAfterSeconds
must equal expires / 1000
.
1 2var express = require('express'); 3var session = require('express-session'); 4var MongoDBStore = require('connect-mongodb-session')(session); 5 6var store = new MongoDBStore({ 7 uri: 'mongodb://username:password@cosmosdb-name.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@cosmosdb-name@', 8 databaseName: 'myDb', 9 collection: 'mySessions', 10 11 // Change the expires key name 12 expiresKey: `_ts`, 13 // This controls the life of the document - set to same value as expires / 1000 14 expiresAfterSeconds: 60 * 60 * 24 * 14 15});
No vulnerabilities found.
No security vulnerabilities found.