A MySQL session store for express.js
Add to your application via npm
:
npm install express-mysql-session --save
This will install express-mysql-session
and add it to your application's package.json
file.
To use express-mysql-session
, simply use it with your express session middleware, like this:
var express = require('express')
var app = module.exports = express()
var session = require('express-session')
var SessionStore = require('express-mysql-session')
var options = {
host: 'localhost',
port: 3306,
user: 'session_test',
password: 'password',
database: 'session_test'
}
app.use(session({
key: 'session_cookie_name',
secret: 'session_cookie_secret',
store: new SessionStore(options)
}))
Here is a list of all available options:
var options = {
host: 'localhost',// Host name for database connection.
port: 3306,// Port number for database connection.
user: 'session_test',// Database user.
password: 'password',// Password for the above database user.
database: 'session_test',// Database name.
debug: false,// Whether or not to output debug messages to the console.
checkExpirationInterval: 900000,// How frequently expired sessions will be cleared; milliseconds.
expiration: 86400000,// The maximum age of a valid session; milliseconds.
autoReconnect: true,// Whether or not to re-establish a database connection after a disconnect.
reconnectDelay: 200,// Time between reconnection attempts; milliseconds
maxReconnectAttempts: 25,// Maximum number of reconnection attempts. Set to 0 for unlimited.
useConnectionPooling: false// Sets whether session should use connection pooling or not.
}
There are a number of ways you can contribute:
- Improve or correct the documentation - All the documentation is in this
readme.md
file. If you see a mistake, or think something should be clarified or expanded upon, please submit a pull request - Report a bug - Please review existing issues before submitting a new one; to avoid duplicates. If you can't find an issue that relates to the bug you've found, please create a new one.
- Fix a bug - Have a look at the existing issues for the project. If there's a bug in there that you'd like to tackle, please feel free to do so. I would ask that when fixing a bug, that you first create a failing test that proves the bug. Then to fix the bug, make the test pass. This should hopefully ensure that the bug never creeps into the project again. After you've done all that, you can submit a pull request with your changes.
Before you contribute code, please read through at least some of the source code for the project. I would appreciate it if any pull requests for source code changes follow the coding style of the rest of the project.
Now if you're still interested, you'll need to get your local environment configured.
First, you'll need to pull down the code from GitHub:
git clone [email protected]:chill117/express-mysql-session.git
Second, you'll need to install the project dependencies as well as the dev dependencies. To do this, simply run the following from the directory you created in step 1:
npm install
Now, you'll need to set up a local test database:
{
host: 'localhost',
port: 3306,
user: 'session_test',
password: 'password',
database: 'session_test'
}
These database credentials are located at test/config/database.js
With your local environment configured, running tests is as simple as:
npm test