express-session
'express-session' 은 서버가 web sessions를 사용할 수 있게 해주는 middleware 이다.
* express-session middleware는 cookie-parser이 먼저 선언되어 있어야 사용 할 수 있다.
express-session의 사용 형태
var express = require('express'); var app = express(); var cookieParser = require('cookie-parser'); app.use(cookieParser()); var session = require('express-session'); app.use(session({ secret:'keyboard cat', cookie: {secure:true} ... });
express-session 의 옵션들
- key: Cookie name, defaulting to connect.sid
- store: Session store instance, usually a Redis object
- secret: Used to sign the session cookie, to prevent tampering; usually just a random string
- cookie: Session cookie settings, defaulting to { path: '/', httpOnly: true, maxAge: null }
- proxy: Boolean that indicates whether to trust the reverse proxy when setting secure cookies (via "X-Forwarded-Proto")
- saveUninitialized: Boolean that forces the saving of a new session (default is true)
- unset: Controls if you want to keep the session in the store after unsetting the session with possible values keep and destroy (default is keep)
- resave: Boolean that forces the saving of the unmodified session (default is true)
- rolling: Boolean that sets a new cookie on each request which resets the expiration (default is false)
- genid: A function that generates session ID (default is uid2:https://www.npmjs.org/package/uid2, https://github.com/coreh/uid2)