Registry / storage / express-mysql2-session

express-mysql2-session

JSON →
library1.0.1jsnpmunverified

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.

storage
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'));
Debug
Known footguns
breakingConstructor signature changed in v1.0.0: the session argument is now a function call, not a constructor.
deprecatedThe mysql npm package is no longer maintained. It is recommended to use mysql2 if possible.
gotchaThe session table is created with utf8mb4 collation, which requires MySQL 5.5.3+. Older MySQL versions will fail to create the table automatically.
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.

Agent activity
10 hits · last 30 days
gptbot
3
amazonbot
3
bytedance
2
Resources