GithubHelp home page GithubHelp logo

ravenscar / express-mysql-session Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chill117/express-mysql-session

0.0 2.0 0.0 220 KB

A MySQL session store for express.js

License: MIT License

JavaScript 100.00%

express-mysql-session's Introduction

express-mysql-session Build Status

A MySQL session store for express.js

Installation

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.

How to Use

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)
}))

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.
	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: [
		500,// Time between each attempt in the first group of reconnection attempts; milliseconds.
		1000,// Time between each attempt in the second group of reconnection attempts; milliseconds.
		5000,// Time between each attempt in the third group of reconnection attempts; milliseconds.
		30000,// Time between each attempt in the fourth group of reconnection attempts; milliseconds.
		300000// Time between each attempt in the fifth group of reconnection attempts; milliseconds.
	],
	reconnectDelayGroupSize: 5,// Number of reconnection attempts per reconnect delay value.
	maxReconnectAttempts: 25,// Maximum number of reconnection attempts. Set to 0 for unlimited.
	useConnectionPooling: false,// Whether or not to use connection pooling.
	keepAlive: true,// Whether or not to send keep-alive pings on the database connection.
	keepAliveInterval: 30000,// How frequently keep-alive pings will be sent; milliseconds.
}

Reconnect Delays

The reconnect-related options may require a bit of additional explanation. With the default options shown above, the reconnect attempts will have the following delay pattern:

  • Attempts #1 through #5 will have a delay of 500 milliseconds each.
  • Attempts #6 through #10 will have a delay of 1 second each.
  • Attempts #11 through #15 will have a delay of 5 seconds each.
  • Attempts #16 through #20 will have a delay of 30 seconds each.
  • Attempts #21 through #25 will have a delay of 5 minutes each.

If the reconnectDelayGroupSize was 3:

  • Attempts #1 through #3 will have a delay of 500 milliseconds each.
  • Attempts #4 through #6 will have a delay of 1 second each.
  • Attempts #7 through #9 will have a delay of 5 seconds each.
  • Attempts #10 through #12 will have a delay of 30 seconds each.
  • Attempts #13 through #25 will have a delay of 5 minutes each.

Any reconnect attempts beyond the last value in the reconnectDelay array will simply use the last value from the reconnectDelay array.

Alternatively you may supply a single integer value to the reconnectDelay option to have one delay time between all reconnect attempts, like this:

var options = {
	reconnectDelay: 500
}

Debugging

express-mysql-session uses the debug module to output debug messages to the console. To output all debug messages, run your node app with the DEBUG environment variable:

DEBUG=express-mysql-session* node your-app.js

This will output log messages as well as error messages from express-mysql-session.

If you also might need MySQL-related debug and error messages, include mysql-connection-manager as well:

DEBUG=express-mysql-session*,mysql-connection-manager* node your-app.js

Contributing

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.
  • Request a feature - Again, please review the existing issues before posting a feature request. If you can't find an existing one that covers your feature idea, 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.

Configure Local Environment

Step 1: Get the Code

First, you'll need to pull down the code from GitHub:

git clone [email protected]:chill117/express-mysql-session.git

Step 2: Install Dependencies

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

Step 3: Set Up the Test Database

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

Running Tests

With your local environment configured, running tests is as simple as:

npm test

This module supports node.js 0.8.x and 0.10.x. If you are planning to contribute, please test your changes against all supported versions of node. If you need help setting up multiple versions of node in your development environment, this article can guide you through the process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.