A MySQL session store for express.js, version 1.0.1. This package provides a session store implementation backed by MySQL, designed to work with the express-session middleware. It uses the mysql npm package internally but also supports passing an existing connection or pool. The store creates a session table automatically and supports custom table schemas. It is actively maintained and ships TypeScript type definitions.
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
The package exports a function that must be called with the express-session object.
const MySQLStore = require('express-mysql-session')(session);
TypeScript ESM import requires calling the default export with express-session.
import session from 'express-session'; import MySQLStore from 'express-mysql-session'; const store = MySQLStore(session);
You must pass the session constructor to the required function.
const MySQLStore = require('express-mysql-session')(require('express-session'));
Basic setup of express-mysql-session with express-session, creating a session store with MySQL connection options.
const express = require('express');
const session = require('express-session');
const MySQLStore = require('express-mysql-session')(session);
const app = express();
const options = {
host: process.env.MYSQL_HOST ?? 'localhost',
port: parseInt(process.env.MYSQL_PORT ?? '3306'),
user: process.env.MYSQL_USER ?? 'root',
password: process.env.MYSQL_PASSWORD ?? '',
database: process.env.MYSQL_DATABASE ?? 'test'
};
const sessionStore = new MySQLStore(options);
app.use(session({
secret: 'secret',
store: sessionStore,
resave: false,
saveUninitialized: false
}));
app.get('/', (req, res) => {
if (req.session.views) {
req.session.views++;
} else {
req.session.views = 1;
}
res.send(`Views: ${req.session.views}`);
});
app.listen(3000, () => console.log('Server running on port 3000'));
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.