Gathering detailed insights and metrics for session-store-js
Gathering detailed insights and metrics for session-store-js
Gathering detailed insights and metrics for session-store-js
Gathering detailed insights and metrics for session-store-js
express-elasticsearch-session
ElasticSearch session store, using elasticsearch-js for communications with server
connect-cloudant-store
Node JS express-session storage connector for IBM Cloudant
node-disk-storage
fast and secure local storage persistent data for node js
ng-cryptostore
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.10. to store data (string, object or array of objects) in local stores or the session store with crypto-js package
npm install session-store-js
Typescript
Module System
Node Version
NPM Version
59.2
Supply Chain
94
Quality
74.1
Maintenance
100
Vulnerability
100
License
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-66.7%
1
Compared to previous week
Last Month
-58.8%
7
Compared to previous month
Last Year
0%
221
Compared to previous year
This package provides a robust and flexible session management solution for Express.js applications. It supports two types of session storage: MemoryStore for in-memory storage and FileStore for file system persistence.
To install PryxAPI, run the following command in your project directory:
1npm install session-store-js
Dual Storage Support
: Choose between MemoryStore for quick, non-persistent sessions, or FileStore for persistent sessions.Express.js Integration
: Seamlessly integrates as Express middleware.Asynchronous API
: All session operations are asynchronous for improved performance.Automatic Cookie Management
: Handles session cookies with security in mind.Comprehensive Session Operations
: Includes methods for getting, setting, destroying, and touching sessions.Session Overview
: Provides methods to retrieve all active sessions and clear them globally.Advanced Store Management
: Includes methods to control cleanup and maintenance processes for both MemoryStore and FileStore.To use the SessionManager, first import it and create an instance::
1const SessionManager = require('session-store-js'); 2 3const sessionManager = new SessionManager({ 4 storeType: 'memory', // or 'file' 5 storeOptions: {}, // options specific to the store type 6 secret: 'your-secret-key', 7 cookieName: 'custom.sid', 8 maxAge: 3600000 // 1 hour 9});
storeType
: Choose 'memory' or 'file'.
storeOptions
: Configuration for the chosen store type.
MemoryStore options:
maxAge
: Maximum session age (milliseconds).cleanupInterval
: Interval for clearing expired sessions (milliseconds).indexInterval
: Interval for rebuilding the expiration index (milliseconds).FileStore options:
path
: Directory for storing session files.ttl
: Session time-to-live (seconds).secret
: Secret key for signing cookies.
cookieName
: Custom name for the session cookie.
maxAge
: Session lifetime (milliseconds).
Apply the session middleware to your Express app:
1app.use(sessionManager.middleware());
1const value = await sessionManager.get(req, 'key');
1await sessionManager.set(req, 'key', 'value');
1await sessionManager.destroy(req);
1await sessionManager.touch(req);
1const sessions = await sessionManager.getAllSessions();
1await sessionManager.clearAllSessions();
1sessionManager.store.startCleanup();
1sessionManager.store.stopCleanup();
1sessionManager.store.startIndexRebuild();
1sessionManager.store.stopIndexRebuild();
1const filePath = sessionManager.store._getFilePath(sessionId);
1sessionManager.store.stopCleanup();
1const express = require('express'); 2const cookieParser = require('cookie-parser'); 3const SessionManager = require('session-store-js'); 4 5const app = express(); 6app.use(cookieParser()); 7 8const sessionManager = new SessionManager({ 9 storeType: 'memory', 10 storeOptions: { 11 cleanupInterval: 300000, // 5 minutes 12 indexInterval: 60000 // 1 minute 13 }, 14 secret: 'your-secret-key', 15 cookieName: 'my.session.id', 16 maxAge: 3600000 // 1 hour 17}); 18 19app.use(sessionManager.middleware()); 20 21app.get('/', async (req, res) => { 22 const visitCount = (await sessionManager.get(req, 'visits') || 0) + 1; 23 await sessionManager.set(req, 'visits', visitCount); 24 res.send(`Welcome! You've visited this page ${visitCount} times.`); 25}); 26 27app.get('/touch', async (req, res) => { 28 await sessionManager.touch(req); 29 res.send('Session touched'); 30}); 31 32app.get('/logout', async (req, res) => { 33 await sessionManager.destroy(req); 34 res.send('Logged out successfully'); 35}); 36 37app.get('/all-sessions', async (req, res) => { 38 const sessions = await sessionManager.getAllSessions(); 39 res.json(sessions); 40}); 41 42app.get('/clear-all', async (req, res) => { 43 await sessionManager.clearAllSessions(); 44 res.send('All sessions cleared'); 45}); 46 47app.get('/start-cleanup', (req, res) => { 48 sessionManager.store.startCleanup(); 49 res.send('Cleanup started'); 50}); 51 52app.get('/stop-cleanup', (req, res) => { 53 sessionManager.store.stopCleanup(); 54 res.send('Cleanup stopped'); 55}); 56 57app.get('/start-index-rebuild', (req, res) => { 58 sessionManager.store.startIndexRebuild(); 59 res.send('Index rebuild started'); 60}); 61 62app.get('/stop-index-rebuild', (req, res) => { 63 sessionManager.store.stopIndexRebuild(); 64 res.send('Index rebuild stopped'); 65}); 66 67app.listen(3000, () => console.log('MemoryStore server running on port 3000'));
1const express = require('express'); 2const cookieParser = require('cookie-parser'); 3const SessionManager = require('session-store-js'); 4 5const app = express(); 6app.use(cookieParser()); 7 8const sessionManager = new SessionManager({ 9 storeType: 'file', 10 storeOptions: { 11 path: './sessions', 12 ttl: 86400, // 1 day in seconds 13 }, 14 secret: 'your-file-secret-key', 15 cookieName: 'my.file.session.id', 16 maxAge: 86400000 // 1 day in milliseconds 17}); 18 19app.use(sessionManager.middleware()); 20 21app.get('/', async (req, res) => { 22 const visitCount = (await sessionManager.get(req, 'visits') || 0) + 1; 23 await sessionManager.set(req, 'visits', visitCount); 24 res.send(`Welcome! You've visited this page ${visitCount} times.`); 25}); 26 27app.get('/touch', async (req, res) => { 28 await sessionManager.touch(req); 29 res.send('Session touched'); 30}); 31 32app.get('/logout', async (req, res) => { 33 await sessionManager.destroy(req); 34 res.send('Logged out successfully'); 35}); 36 37app.get('/all-sessions', async (req, res) => { 38 const sessions = await sessionManager.getAllSessions(); 39 res.json(sessions); 40}); 41 42app.get('/clear-all', async (req, res) => { 43 await sessionManager.clearAllSessions(); 44 res.send('All sessions cleared'); 45}); 46 47app.get('/ensure-directory', async (req, res) => { 48 await sessionManager.store.ensureDirectory(); 49 res.send('Session directory ensured'); 50}); 51 52app.get('/file-path', (req, res) => { 53 if (req.sessionID) { 54 const filePath = sessionManager.store._getFilePath(req.sessionID); 55 res.send(`Session file path: ${filePath}`); 56 } else { 57 res.status(400).send('No active session'); 58 } 59}); 60 61app.listen(3001, () => console.log('FileStore server running on port 3001'));
Both examples demonstrate the consistent API across different storage types, while also showcasing store-specific operations.
This comprehensive guide covers the usage of your SessionManager package with both MemoryStore and FileStore, including common operations and store-specific functionalities. It provides developers with the necessary information to effectively implement and manage sessions in their Express.js applications using your package.
No vulnerabilities found.
No security vulnerabilities found.