5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.js + Express4でセッションを使いたい

Last updated at Posted at 2015-07-01

Node.js + Express4でセッションを使うときをMySQLを使いたい。
以下個人的なメモ。 MySQLはインストール済みが前提

こちらのサイトを参考にしました。
https://github.com/expressjs/session
https://github.com/nlf/connect-mysql
http://qiita.com/zaru/items/68b4f64c1f0d10b6a27e

・インストール
$ npm install express-session
$ npm installconnect-mysql

・packaeg.jsonに追記
・読み込み。
var session = require('express-session');

var MySQLStore = require('connect-mysql')(session),
options = {
secret: 'hoge',
config: {
host: "",
database: "
",
user: "",
password: "
"
}
};

app.use(session({
store: new MySQLStore(options),
secret: 'hoge'
}));

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?