npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

connect-mysql

v4.0.0

Published

a MySQL session store for connect

Downloads

2,863

Readme

connect-mysql

This is a simple MySQL backed session store for connect.

It uses the node-mysql module already installed in your project to establish and pool connections.

Upgrading

Changes introduced in v2.2 mean sessions stored in earlier versions are not backwards compatible with v2.2. It it recommended that you clear the session table; alternately sessions will be discarded with a warning message.

Options

  • table: the name of the database table that should be used for storing sessions. Defaults to 'sessions'
  • pool: a node-mysql connection pool or true if the store should instantiate its own pool
  • config: the configuration that will be passed to createConnection() or createPool() if pool is true
  • retries: how many times to retry connecting to the database before failing. Defaults to 3
  • keepalive: keep pooled connections open by periodically pinging them. Set to true to use the default interval of 30000 ms or provide a positive number to set your own. Defaults to true.
  • cleanup: a boolean specifying whether to enable the cleanup events. note that if this is disabled, cleanup will not take place at all and should be done externally. Sessions with an expiration time of 0 will always be ignored and should also be cleaned up externally.
  • secret: key that will be used to encrypt session data. If this option is not provided then data will be stored in plain text
  • algorithm: the algorithm that should be used to encrypt session data. Defaults to 'aes-256-ctr'

Examples

Here are some example use cases to get your application up and running.

Default use case

Simple use case using the express framework & connect-session middleware with connect-mysql as the data store.

var express = require('express'), // express framework
    session = require('express-session'), // session middleware
    cookieParser = require('cookie-parser'), // cookie middleware
    MySQLStore = require('connect-mysql')(session), // mysql session store
    options = {
      config: {
        user: 'username', 
        password: 'password',
        database: 'databasename' 
      }
    },
    app = express();

app.use(cookieParser());

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true,
  cookie: {
    httpOnly: false,
    secure: false,
    maxAge: 1000 * 60 * 60 * 24 * 3,
    expires: 1000 * 60 * 60 * 24 * 3
  },
  store: new MySQLStore(options) // Change the express session store
}));

app.get('/', function (req, res) {
  if (req.session.views) {
    req.session.views++
  } else {
    req.session.views = 1;
  }

  res.send('Hello world! '+req.session.views);
});
 
app.listen(3000, 'localhost');

Connection pooling example

For those MySQL installations that make use of pools the following examples are available.

  var mysql = require('mysql'),
      options = {
        pool: mysql.createPool({
          user: 'dbuser',
          password: 'dbpassword',
          database: 'db'
        })
      };

Or

var options = {
      pool: true,
      config: {
        user: 'dbuser', 
        password: 'dbpassword', 
        database: 'db' 
      }
    };

Ssession encryption example

This option enables transparent session encryption assisting

var options = {
      secret: 'thesessionsecret',
      config: {
        user: 'dbuser', 
        password: 'dbpassword', 
        database: 'db' 
      }
   };

contributing

Contributions are welcome & appreciated. Refer to the contributing document to help facilitate pull requests.

license

This software is licensed under the MIT License.

Nathan LaFreniere, Copyright (c) 2012 &Yet