
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
session-store-js
Advanced tools
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.
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:
npm 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::
const SessionManager = require('session-store-js');
const sessionManager = new SessionManager({
storeType: 'memory', // or 'file'
storeOptions: {}, // options specific to the store type
secret: 'your-secret-key',
cookieName: 'custom.sid',
maxAge: 3600000 // 1 hour
});
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:
app.use(sessionManager.middleware());
const value = await sessionManager.get(req, 'key');
await sessionManager.set(req, 'key', 'value');
await sessionManager.destroy(req);
await sessionManager.touch(req);
const sessions = await sessionManager.getAllSessions();
await sessionManager.clearAllSessions();
sessionManager.store.startCleanup();
sessionManager.store.stopCleanup();
sessionManager.store.startIndexRebuild();
sessionManager.store.stopIndexRebuild();
const filePath = sessionManager.store._getFilePath(sessionId);
sessionManager.store.stopCleanup();
const express = require('express');
const cookieParser = require('cookie-parser');
const { SessionManager } = require('session-store-js');
const app = express();
app.use(cookieParser());
const sessionManager = new SessionManager({
storeType: 'memory',
storeOptions: {
cleanupInterval: 300000, // 5 minutes
indexInterval: 60000 // 1 minute
},
secret: 'your-secret-key',
cookieName: 'my.session.id',
maxAge: 3600000 // 1 hour
});
app.use(sessionManager.middleware());
app.get('/', async (req, res) => {
const visitCount = (await sessionManager.get(req, 'visits') || 0) + 1;
await sessionManager.set(req, 'visits', visitCount);
res.send(`Welcome! You've visited this page ${visitCount} times.`);
});
app.get('/touch', async (req, res) => {
await sessionManager.touch(req);
res.send('Session touched');
});
app.get('/logout', async (req, res) => {
await sessionManager.destroy(req);
res.send('Logged out successfully');
});
app.get('/all-sessions', async (req, res) => {
const sessions = await sessionManager.getAllSessions();
res.json(sessions);
});
app.get('/clear-all', async (req, res) => {
await sessionManager.clearAllSessions();
res.send('All sessions cleared');
});
app.get('/start-cleanup', (req, res) => {
sessionManager.store.startCleanup();
res.send('Cleanup started');
});
app.get('/stop-cleanup', (req, res) => {
sessionManager.store.stopCleanup();
res.send('Cleanup stopped');
});
app.get('/start-index-rebuild', (req, res) => {
sessionManager.store.startIndexRebuild();
res.send('Index rebuild started');
});
app.get('/stop-index-rebuild', (req, res) => {
sessionManager.store.stopIndexRebuild();
res.send('Index rebuild stopped');
});
app.listen(3000, () => console.log('MemoryStore server running on port 3000'));
const express = require('express');
const cookieParser = require('cookie-parser');
const { SessionManager } = require('session-store-js');
const app = express();
app.use(cookieParser());
const sessionManager = new SessionManager({
storeType: 'file',
storeOptions: {
path: './sessions',
ttl: 86400, // 1 day in seconds
},
secret: 'your-file-secret-key',
cookieName: 'my.file.session.id',
maxAge: 86400000 // 1 day in milliseconds
});
app.use(sessionManager.middleware());
app.get('/', async (req, res) => {
const visitCount = (await sessionManager.get(req, 'visits') || 0) + 1;
await sessionManager.set(req, 'visits', visitCount);
res.send(`Welcome! You've visited this page ${visitCount} times.`);
});
app.get('/touch', async (req, res) => {
await sessionManager.touch(req);
res.send('Session touched');
});
app.get('/logout', async (req, res) => {
await sessionManager.destroy(req);
res.send('Logged out successfully');
});
app.get('/all-sessions', async (req, res) => {
const sessions = await sessionManager.getAllSessions();
res.json(sessions);
});
app.get('/clear-all', async (req, res) => {
await sessionManager.clearAllSessions();
res.send('All sessions cleared');
});
app.get('/ensure-directory', async (req, res) => {
await sessionManager.store.ensureDirectory();
res.send('Session directory ensured');
});
app.get('/file-path', (req, res) => {
if (req.sessionID) {
const filePath = sessionManager.store._getFilePath(req.sessionID);
res.send(`Session file path: ${filePath}`);
} else {
res.status(400).send('No active session');
}
});
app.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.
FAQs
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.
We found that session-store-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.