fe5076d813e72dc3355a0dc42facfc57ea4aa68e
[platform/framework/web/wrtjs.git] / device_home / node_modules / express-session / README.md
1 # express-session
2
3 [![NPM Version][npm-version-image]][npm-url]
4 [![NPM Downloads][npm-downloads-image]][node-url]
5 [![Build Status][travis-image]][travis-url]
6 [![Test Coverage][coveralls-image]][coveralls-url]
7
8 ## Installation
9
10 This is a [Node.js](https://nodejs.org/en/) module available through the
11 [npm registry](https://www.npmjs.com/). Installation is done using the
12 [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
13
14 ```sh
15 $ npm install express-session
16 ```
17
18 ## API
19
20 ```js
21 var session = require('express-session')
22 ```
23
24 ### session(options)
25
26 Create a session middleware with the given `options`.
27
28 **Note** Session data is _not_ saved in the cookie itself, just the session ID.
29 Session data is stored server-side.
30
31 **Note** Since version 1.5.0, the [`cookie-parser` middleware](https://www.npmjs.com/package/cookie-parser)
32 no longer needs to be used for this module to work. This module now directly reads
33 and writes cookies on `req`/`res`. Using `cookie-parser` may result in issues
34 if the `secret` is not the same between this module and `cookie-parser`.
35
36 **Warning** The default server-side session storage, `MemoryStore`, is _purposely_
37 not designed for a production environment. It will leak memory under most
38 conditions, does not scale past a single process, and is meant for debugging and
39 developing.
40
41 For a list of stores, see [compatible session stores](#compatible-session-stores).
42
43 #### Options
44
45 `express-session` accepts these properties in the options object.
46
47 ##### cookie
48
49 Settings object for the session ID cookie. The default value is
50 `{ path: '/', httpOnly: true, secure: false, maxAge: null }`.
51
52 The following are options that can be set in this object.
53
54 ##### cookie.domain
55
56 Specifies the value for the `Domain` `Set-Cookie` attribute. By default, no domain
57 is set, and most clients will consider the cookie to apply to only the current
58 domain.
59
60 ##### cookie.expires
61
62 Specifies the `Date` object to be the value for the `Expires` `Set-Cookie` attribute.
63 By default, no expiration is set, and most clients will consider this a
64 "non-persistent cookie" and will delete it on a condition like exiting a web browser
65 application.
66
67 **Note** If both `expires` and `maxAge` are set in the options, then the last one
68 defined in the object is what is used.
69
70 **Note** The `expires` option should not be set directly; instead only use the `maxAge`
71 option.
72
73 ##### cookie.httpOnly
74
75 Specifies the `boolean` value for the `HttpOnly` `Set-Cookie` attribute. When truthy,
76 the `HttpOnly` attribute is set, otherwise it is not. By default, the `HttpOnly`
77 attribute is set.
78
79 **Note** be careful when setting this to `true`, as compliant clients will not allow
80 client-side JavaScript to see the cookie in `document.cookie`.
81
82 ##### cookie.maxAge
83
84 Specifies the `number` (in milliseconds) to use when calculating the `Expires`
85 `Set-Cookie` attribute. This is done by taking the current server time and adding
86 `maxAge` milliseconds to the value to calculate an `Expires` datetime. By default,
87 no maximum age is set.
88
89 **Note** If both `expires` and `maxAge` are set in the options, then the last one
90 defined in the object is what is used.
91
92 ##### cookie.path
93
94 Specifies the value for the `Path` `Set-Cookie`. By default, this is set to `'/'`, which
95 is the root path of the domain.
96
97 ##### cookie.sameSite
98
99 Specifies the `boolean` or `string` to be the value for the `SameSite` `Set-Cookie` attribute.
100
101   - `true` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
102   - `false` will not set the `SameSite` attribute.
103   - `'lax'` will set the `SameSite` attribute to `Lax` for lax same site enforcement.
104   - `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
105   - `'strict'` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
106
107 More information about the different enforcement levels can be found in
108 [the specification][rfc-6265bis-03-4.1.2.7].
109
110 **Note** This is an attribute that has not yet been fully standardized, and may change in
111 the future. This also means many clients may ignore this attribute until they understand it.
112
113 ##### cookie.secure
114
115 Specifies the `boolean` value for the `Secure` `Set-Cookie` attribute. When truthy,
116 the `Secure` attribute is set, otherwise it is not. By default, the `Secure`
117 attribute is not set.
118
119 **Note** be careful when setting this to `true`, as compliant clients will not send
120 the cookie back to the server in the future if the browser does not have an HTTPS
121 connection.
122
123 Please note that `secure: true` is a **recommended** option. However, it requires
124 an https-enabled website, i.e., HTTPS is necessary for secure cookies. If `secure`
125 is set, and you access your site over HTTP, the cookie will not be set. If you
126 have your node.js behind a proxy and are using `secure: true`, you need to set
127 "trust proxy" in express:
128
129 ```js
130 var app = express()
131 app.set('trust proxy', 1) // trust first proxy
132 app.use(session({
133   secret: 'keyboard cat',
134   resave: false,
135   saveUninitialized: true,
136   cookie: { secure: true }
137 }))
138 ```
139
140 For using secure cookies in production, but allowing for testing in development,
141 the following is an example of enabling this setup based on `NODE_ENV` in express:
142
143 ```js
144 var app = express()
145 var sess = {
146   secret: 'keyboard cat',
147   cookie: {}
148 }
149
150 if (app.get('env') === 'production') {
151   app.set('trust proxy', 1) // trust first proxy
152   sess.cookie.secure = true // serve secure cookies
153 }
154
155 app.use(session(sess))
156 ```
157
158 The `cookie.secure` option can also be set to the special value `'auto'` to have
159 this setting automatically match the determined security of the connection. Be
160 careful when using this setting if the site is available both as HTTP and HTTPS,
161 as once the cookie is set on HTTPS, it will no longer be visible over HTTP. This
162 is useful when the Express `"trust proxy"` setting is properly setup to simplify
163 development vs production configuration.
164
165 ##### genid
166
167 Function to call to generate a new session ID. Provide a function that returns
168 a string that will be used as a session ID. The function is given `req` as the
169 first argument if you want to use some value attached to `req` when generating
170 the ID.
171
172 The default value is a function which uses the `uid-safe` library to generate IDs.
173
174 **NOTE** be careful to generate unique IDs so your sessions do not conflict.
175
176 ```js
177 app.use(session({
178   genid: function(req) {
179     return genuuid() // use UUIDs for session IDs
180   },
181   secret: 'keyboard cat'
182 }))
183 ```
184
185 ##### name
186
187 The name of the session ID cookie to set in the response (and read from in the
188 request).
189
190 The default value is `'connect.sid'`.
191
192 **Note** if you have multiple apps running on the same hostname (this is just
193 the name, i.e. `localhost` or `127.0.0.1`; different schemes and ports do not
194 name a different hostname), then you need to separate the session cookies from
195 each other. The simplest method is to simply set different `name`s per app.
196
197 ##### proxy
198
199 Trust the reverse proxy when setting secure cookies (via the "X-Forwarded-Proto"
200 header).
201
202 The default value is `undefined`.
203
204   - `true` The "X-Forwarded-Proto" header will be used.
205   - `false` All headers are ignored and the connection is considered secure only
206     if there is a direct TLS/SSL connection.
207   - `undefined` Uses the "trust proxy" setting from express
208
209 ##### resave
210
211 Forces the session to be saved back to the session store, even if the session
212 was never modified during the request. Depending on your store this may be
213 necessary, but it can also create race conditions where a client makes two
214 parallel requests to your server and changes made to the session in one
215 request may get overwritten when the other request ends, even if it made no
216 changes (this behavior also depends on what store you're using).
217
218 The default value is `true`, but using the default has been deprecated,
219 as the default will change in the future. Please research into this setting
220 and choose what is appropriate to your use-case. Typically, you'll want
221 `false`.
222
223 How do I know if this is necessary for my store? The best way to know is to
224 check with your store if it implements the `touch` method. If it does, then
225 you can safely set `resave: false`. If it does not implement the `touch`
226 method and your store sets an expiration date on stored sessions, then you
227 likely need `resave: true`.
228
229 ##### rolling
230
231 Force the session identifier cookie to be set on every response. The expiration
232 is reset to the original [`maxAge`](#cookiemaxage), resetting the expiration
233 countdown.
234
235 The default value is `false`.
236
237 With this enabled, the session identifier cookie will expire in
238 [`maxAge`](#cookiemaxage) since the last response was sent instead of in
239 [`maxAge`](#cookiemaxage) since the session was last modified by the server.
240
241 This is typically used in conjuction with short, non-session-length
242 [`maxAge`](#cookiemaxage) values to provide a quick timeout of the session data
243 with reduced potentional of it occurring during on going server interactions.
244
245 **Note** When this option is set to `true` but the `saveUninitialized` option is
246 set to `false`, the cookie will not be set on a response with an uninitialized
247 session. This option only modifies the behavior when an existing session was
248 loaded for the request.
249
250 ##### saveUninitialized
251
252 Forces a session that is "uninitialized" to be saved to the store. A session is
253 uninitialized when it is new but not modified. Choosing `false` is useful for
254 implementing login sessions, reducing server storage usage, or complying with
255 laws that require permission before setting a cookie. Choosing `false` will also
256 help with race conditions where a client makes multiple parallel requests
257 without a session.
258
259 The default value is `true`, but using the default has been deprecated, as the
260 default will change in the future. Please research into this setting and
261 choose what is appropriate to your use-case.
262
263 **Note** if you are using Session in conjunction with PassportJS, Passport
264 will add an empty Passport object to the session for use after a user is
265 authenticated, which will be treated as a modification to the session, causing
266 it to be saved. *This has been fixed in PassportJS 0.3.0*
267
268 ##### secret
269
270 **Required option**
271
272 This is the secret used to sign the session ID cookie. This can be either a string
273 for a single secret, or an array of multiple secrets. If an array of secrets is
274 provided, only the first element will be used to sign the session ID cookie, while
275 all the elements will be considered when verifying the signature in requests.
276
277 ##### store
278
279 The session store instance, defaults to a new `MemoryStore` instance.
280
281 ##### unset
282
283 Control the result of unsetting `req.session` (through `delete`, setting to `null`,
284 etc.).
285
286 The default value is `'keep'`.
287
288   - `'destroy'` The session will be destroyed (deleted) when the response ends.
289   - `'keep'` The session in the store will be kept, but modifications made during
290     the request are ignored and not saved.
291
292 ### req.session
293
294 To store or access session data, simply use the request property `req.session`,
295 which is (generally) serialized as JSON by the store, so nested objects
296 are typically fine. For example below is a user-specific view counter:
297
298 ```js
299 // Use the session middleware
300 app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
301
302 // Access the session as req.session
303 app.get('/', function(req, res, next) {
304   if (req.session.views) {
305     req.session.views++
306     res.setHeader('Content-Type', 'text/html')
307     res.write('<p>views: ' + req.session.views + '</p>')
308     res.write('<p>expires in: ' + (req.session.cookie.maxAge / 1000) + 's</p>')
309     res.end()
310   } else {
311     req.session.views = 1
312     res.end('welcome to the session demo. refresh!')
313   }
314 })
315 ```
316
317 #### Session.regenerate(callback)
318
319 To regenerate the session simply invoke the method. Once complete,
320 a new SID and `Session` instance will be initialized at `req.session`
321 and the `callback` will be invoked.
322
323 ```js
324 req.session.regenerate(function(err) {
325   // will have a new session here
326 })
327 ```
328
329 #### Session.destroy(callback)
330
331 Destroys the session and will unset the `req.session` property.
332 Once complete, the `callback` will be invoked.
333
334 ```js
335 req.session.destroy(function(err) {
336   // cannot access session here
337 })
338 ```
339
340 #### Session.reload(callback)
341
342 Reloads the session data from the store and re-populates the
343 `req.session` object. Once complete, the `callback` will be invoked.
344
345 ```js
346 req.session.reload(function(err) {
347   // session updated
348 })
349 ```
350
351 #### Session.save(callback)
352
353 Save the session back to the store, replacing the contents on the store with the
354 contents in memory (though a store may do something else--consult the store's
355 documentation for exact behavior).
356
357 This method is automatically called at the end of the HTTP response if the
358 session data has been altered (though this behavior can be altered with various
359 options in the middleware constructor). Because of this, typically this method
360 does not need to be called.
361
362 There are some cases where it is useful to call this method, for example,
363 redirects, long-lived requests or in WebSockets.
364
365 ```js
366 req.session.save(function(err) {
367   // session saved
368 })
369 ```
370
371 #### Session.touch()
372
373 Updates the `.maxAge` property. Typically this is
374 not necessary to call, as the session middleware does this for you.
375
376 ### req.session.id
377
378 Each session has a unique ID associated with it. This property is an
379 alias of [`req.sessionID`](#reqsessionid-1) and cannot be modified.
380 It has been added to make the session ID accessible from the `session`
381 object.
382
383 ### req.session.cookie
384
385 Each session has a unique cookie object accompany it. This allows
386 you to alter the session cookie per visitor. For example we can
387 set `req.session.cookie.expires` to `false` to enable the cookie
388 to remain for only the duration of the user-agent.
389
390 #### Cookie.maxAge
391
392 Alternatively `req.session.cookie.maxAge` will return the time
393 remaining in milliseconds, which we may also re-assign a new value
394 to adjust the `.expires` property appropriately. The following
395 are essentially equivalent
396
397 ```js
398 var hour = 3600000
399 req.session.cookie.expires = new Date(Date.now() + hour)
400 req.session.cookie.maxAge = hour
401 ```
402
403 For example when `maxAge` is set to `60000` (one minute), and 30 seconds
404 has elapsed it will return `30000` until the current request has completed,
405 at which time `req.session.touch()` is called to reset
406 `req.session.cookie.maxAge` to its original value.
407
408 ```js
409 req.session.cookie.maxAge // => 30000
410 ```
411
412 #### Cookie.originalMaxAge
413
414 The `req.session.cookie.originalMaxAge` property returns the original
415 `maxAge` (time-to-live), in milliseconds, of the session cookie.
416
417 ### req.sessionID
418
419 To get the ID of the loaded session, access the request property
420 `req.sessionID`. This is simply a read-only value set when a session
421 is loaded/created.
422
423 ## Session Store Implementation
424
425 Every session store _must_ be an `EventEmitter` and implement specific
426 methods. The following methods are the list of **required**, **recommended**,
427 and **optional**.
428
429   * Required methods are ones that this module will always call on the store.
430   * Recommended methods are ones that this module will call on the store if
431     available.
432   * Optional methods are ones this module does not call at all, but helps
433     present uniform stores to users.
434
435 For an example implementation view the [connect-redis](http://github.com/visionmedia/connect-redis) repo.
436
437 ### store.all(callback)
438
439 **Optional**
440
441 This optional method is used to get all sessions in the store as an array. The
442 `callback` should be called as `callback(error, sessions)`.
443
444 ### store.destroy(sid, callback)
445
446 **Required**
447
448 This required method is used to destroy/delete a session from the store given
449 a session ID (`sid`). The `callback` should be called as `callback(error)` once
450 the session is destroyed.
451
452 ### store.clear(callback)
453
454 **Optional**
455
456 This optional method is used to delete all sessions from the store. The
457 `callback` should be called as `callback(error)` once the store is cleared.
458
459 ### store.length(callback)
460
461 **Optional**
462
463 This optional method is used to get the count of all sessions in the store.
464 The `callback` should be called as `callback(error, len)`.
465
466 ### store.get(sid, callback)
467
468 **Required**
469
470 This required method is used to get a session from the store given a session
471 ID (`sid`). The `callback` should be called as `callback(error, session)`.
472
473 The `session` argument should be a session if found, otherwise `null` or
474 `undefined` if the session was not found (and there was no error). A special
475 case is made when `error.code === 'ENOENT'` to act like `callback(null, null)`.
476
477 ### store.set(sid, session, callback)
478
479 **Required**
480
481 This required method is used to upsert a session into the store given a
482 session ID (`sid`) and session (`session`) object. The callback should be
483 called as `callback(error)` once the session has been set in the store.
484
485 ### store.touch(sid, session, callback)
486
487 **Recommended**
488
489 This recommended method is used to "touch" a given session given a
490 session ID (`sid`) and session (`session`) object. The `callback` should be
491 called as `callback(error)` once the session has been touched.
492
493 This is primarily used when the store will automatically delete idle sessions
494 and this method is used to signal to the store the given session is active,
495 potentially resetting the idle timer.
496
497 ## Compatible Session Stores
498
499 The following modules implement a session store that is compatible with this
500 module. Please make a PR to add additional modules :)
501
502 [![★][aerospike-session-store-image] aerospike-session-store][aerospike-session-store-url] A session store using [Aerospike](http://www.aerospike.com/).
503
504 [aerospike-session-store-url]: https://www.npmjs.com/package/aerospike-session-store
505 [aerospike-session-store-image]: https://badgen.net/github/stars/aerospike/aerospike-session-store-expressjs?label=%E2%98%85
506
507 [![★][cassandra-store-image] cassandra-store][cassandra-store-url] An Apache Cassandra-based session store.
508
509 [cassandra-store-url]: https://www.npmjs.com/package/cassandra-store
510 [cassandra-store-image]: https://badgen.net/github/stars/webcc/cassandra-store?label=%E2%98%85
511
512 [![★][cluster-store-image] cluster-store][cluster-store-url] A wrapper for using in-process / embedded
513 stores - such as SQLite (via knex), leveldb, files, or memory - with node cluster (desirable for Raspberry Pi 2
514 and other multi-core embedded devices).
515
516 [cluster-store-url]: https://www.npmjs.com/package/cluster-store
517 [cluster-store-image]: https://badgen.net/github/stars/coolaj86/cluster-store?label=%E2%98%85
518
519 [![★][connect-arango-image] connect-arango][connect-arango-url] An ArangoDB-based session store.
520
521 [connect-arango-url]: https://www.npmjs.com/package/connect-arango
522 [connect-arango-image]: https://badgen.net/github/stars/AlexanderArvidsson/connect-arango?label=%E2%98%85
523
524 [![★][connect-azuretables-image] connect-azuretables][connect-azuretables-url] An [Azure Table Storage](https://azure.microsoft.com/en-gb/services/storage/tables/)-based session store.
525
526 [connect-azuretables-url]: https://www.npmjs.com/package/connect-azuretables
527 [connect-azuretables-image]: https://badgen.net/github/stars/mike-goodwin/connect-azuretables?label=%E2%98%85
528
529 [![★][connect-cloudant-store-image] connect-cloudant-store][connect-cloudant-store-url] An [IBM Cloudant](https://cloudant.com/)-based session store.
530
531 [connect-cloudant-store-url]: https://www.npmjs.com/package/connect-cloudant-store
532 [connect-cloudant-store-image]: https://badgen.net/github/stars/adriantanasa/connect-cloudant-store?label=%E2%98%85
533
534 [![★][connect-couchbase-image] connect-couchbase][connect-couchbase-url] A [couchbase](http://www.couchbase.com/)-based session store.
535
536 [connect-couchbase-url]: https://www.npmjs.com/package/connect-couchbase
537 [connect-couchbase-image]: https://badgen.net/github/stars/christophermina/connect-couchbase?label=%E2%98%85
538
539 [![★][connect-datacache-image] connect-datacache][connect-datacache-url] An [IBM Bluemix Data Cache](http://www.ibm.com/cloud-computing/bluemix/)-based session store.
540
541 [connect-datacache-url]: https://www.npmjs.com/package/connect-datacache
542 [connect-datacache-image]: https://badgen.net/github/stars/adriantanasa/connect-datacache?label=%E2%98%85
543
544 [![★][@google-cloud/connect-datastore-image] @google-cloud/connect-datastore][@google-cloud/connect-datastore-url] A [Google Cloud Datastore](https://cloud.google.com/datastore/docs/concepts/overview)-based session store.
545
546 [@google-cloud/connect-datastore-url]: https://www.npmjs.com/package/@google-cloud/connect-datastore
547 [@google-cloud/connect-datastore-image]: https://badgen.net/github/stars/GoogleCloudPlatform/cloud-datastore-session-node?label=%E2%98%85
548
549 [![★][connect-db2-image] connect-db2][connect-db2-url] An IBM DB2-based session store built using [ibm_db](https://www.npmjs.com/package/ibm_db) module.
550
551 [connect-db2-url]: https://www.npmjs.com/package/connect-db2
552 [connect-db2-image]: https://badgen.net/github/stars/wallali/connect-db2?label=%E2%98%85
553
554 [![★][connect-dynamodb-image] connect-dynamodb][connect-dynamodb-url] A DynamoDB-based session store.
555
556 [connect-dynamodb-url]: https://www.npmjs.com/package/connect-dynamodb
557 [connect-dynamodb-image]: https://badgen.net/github/stars/ca98am79/connect-dynamodb?label=%E2%98%85
558
559 [![★][@google-cloud/connect-firestore-image] @google-cloud/connect-firestore][@google-cloud/connect-firestore-url] A [Google Cloud Firestore](https://cloud.google.com/firestore/docs/overview)-based session store.
560
561 [@google-cloud/connect-firestore-url]: https://www.npmjs.com/package/@google-cloud/connect-firestore
562 [@google-cloud/connect-firestore-image]: https://badgen.net/github/stars/googleapis/nodejs-firestore-session?label=%E2%98%85
563
564 [![★][connect-hazelcast-image] connect-hazelcast][connect-hazelcast-url] Hazelcast session store for Connect and Express.
565
566 [connect-hazelcast-url]: https://www.npmjs.com/package/connect-hazelcast
567 [connect-hazelcast-image]: https://badgen.net/github/stars/huseyinbabal/connect-hazelcast?label=%E2%98%85
568
569 [![★][connect-loki-image] connect-loki][connect-loki-url] A Loki.js-based session store.
570
571 [connect-loki-url]: https://www.npmjs.com/package/connect-loki
572 [connect-loki-image]: https://badgen.net/github/stars/Requarks/connect-loki?label=%E2%98%85
573
574 [![★][connect-memcached-image] connect-memcached][connect-memcached-url] A memcached-based session store.
575
576 [connect-memcached-url]: https://www.npmjs.com/package/connect-memcached
577 [connect-memcached-image]: https://badgen.net/github/stars/balor/connect-memcached?label=%E2%98%85
578
579 [![★][connect-memjs-image] connect-memjs][connect-memjs-url] A memcached-based session store using
580 [memjs](https://www.npmjs.com/package/memjs) as the memcached client.
581
582 [connect-memjs-url]: https://www.npmjs.com/package/connect-memjs
583 [connect-memjs-image]: https://badgen.net/github/stars/liamdon/connect-memjs?label=%E2%98%85
584
585 [![★][connect-ml-image] connect-ml][connect-ml-url] A MarkLogic Server-based session store.
586
587 [connect-ml-url]: https://www.npmjs.com/package/connect-ml
588 [connect-ml-image]: https://badgen.net/github/stars/bluetorch/connect-ml?label=%E2%98%85
589
590 [![★][connect-monetdb-image] connect-monetdb][connect-monetdb-url] A MonetDB-based session store.
591
592 [connect-monetdb-url]: https://www.npmjs.com/package/connect-monetdb
593 [connect-monetdb-image]: https://badgen.net/github/stars/MonetDB/npm-connect-monetdb?label=%E2%98%85
594
595 [![★][connect-mongo-image] connect-mongo][connect-mongo-url] A MongoDB-based session store.
596
597 [connect-mongo-url]: https://www.npmjs.com/package/connect-mongo
598 [connect-mongo-image]: https://badgen.net/github/stars/kcbanner/connect-mongo?label=%E2%98%85
599
600 [![★][connect-mongodb-session-image] connect-mongodb-session][connect-mongodb-session-url] Lightweight MongoDB-based session store built and maintained by MongoDB.
601
602 [connect-mongodb-session-url]: https://www.npmjs.com/package/connect-mongodb-session
603 [connect-mongodb-session-image]: https://badgen.net/github/stars/mongodb-js/connect-mongodb-session?label=%E2%98%85
604
605 [![★][connect-mssql-image] connect-mssql][connect-mssql-url] A SQL Server-based session store.
606
607 [connect-mssql-url]: https://www.npmjs.com/package/connect-mssql
608 [connect-mssql-image]: https://badgen.net/github/stars/patriksimek/connect-mssql?label=%E2%98%85
609
610 [![★][connect-pg-simple-image] connect-pg-simple][connect-pg-simple-url] A PostgreSQL-based session store.
611
612 [connect-pg-simple-url]: https://www.npmjs.com/package/connect-pg-simple
613 [connect-pg-simple-image]: https://badgen.net/github/stars/voxpelli/node-connect-pg-simple?label=%E2%98%85
614
615 [![★][connect-redis-image] connect-redis][connect-redis-url] A Redis-based session store.
616
617 [connect-redis-url]: https://www.npmjs.com/package/connect-redis
618 [connect-redis-image]: https://badgen.net/github/stars/tj/connect-redis?label=%E2%98%85
619
620 [![★][connect-session-firebase-image] connect-session-firebase][connect-session-firebase-url] A session store based on the [Firebase Realtime Database](https://firebase.google.com/docs/database/)
621
622 [connect-session-firebase-url]: https://www.npmjs.com/package/connect-session-firebase
623 [connect-session-firebase-image]: https://badgen.net/github/stars/benweier/connect-session-firebase?label=%E2%98%85
624
625 [![★][connect-session-knex-image] connect-session-knex][connect-session-knex-url] A session store using
626 [Knex.js](http://knexjs.org/), which is a SQL query builder for PostgreSQL, MySQL, MariaDB, SQLite3, and Oracle.
627
628 [connect-session-knex-url]: https://www.npmjs.com/package/connect-session-knex
629 [connect-session-knex-image]: https://badgen.net/github/stars/llambda/connect-session-knex?label=%E2%98%85
630
631 [![★][connect-session-sequelize-image] connect-session-sequelize][connect-session-sequelize-url] A session store using
632 [Sequelize.js](http://sequelizejs.com/), which is a Node.js / io.js ORM for PostgreSQL, MySQL, SQLite and MSSQL.
633
634 [connect-session-sequelize-url]: https://www.npmjs.com/package/connect-session-sequelize
635 [connect-session-sequelize-image]: https://badgen.net/github/stars/mweibel/connect-session-sequelize?label=%E2%98%85
636
637 [![★][connect-sqlite3-image] connect-sqlite3][connect-sqlite3-url] A [SQLite3](https://github.com/mapbox/node-sqlite3) session store modeled after the TJ's `connect-redis` store.
638
639 [connect-sqlite3-url]: https://www.npmjs.com/package/connect-sqlite3
640 [connect-sqlite3-image]: https://badgen.net/github/stars/rawberg/connect-sqlite3?label=%E2%98%85
641
642 [![★][connect-typeorm-image] connect-typeorm][connect-typeorm-url] A [TypeORM](https://github.com/typeorm/typeorm)-based session store.
643
644 [connect-typeorm-url]: https://www.npmjs.com/package/connect-typeorm
645 [connect-typeorm-image]: https://badgen.net/github/stars/makepost/connect-typeorm?label=%E2%98%85
646
647 [![★][couchdb-expression-image] couchdb-expression][couchdb-expression-url] A [CouchDB](https://couchdb.apache.org/)-based session store.
648
649 [couchdb-expression-url]: https://www.npmjs.com/package/couchdb-expression
650 [couchdb-expression-image]: https://badgen.net/github/stars/tkshnwesper/couchdb-expression?label=%E2%98%85
651
652 [![★][documentdb-session-image] documentdb-session][documentdb-session-url] A session store for Microsoft Azure's [DocumentDB](https://azure.microsoft.com/en-us/services/documentdb/) NoSQL database service.
653
654 [documentdb-session-url]: https://www.npmjs.com/package/documentdb-session
655 [documentdb-session-image]: https://badgen.net/github/stars/dwhieb/documentdb-session?label=%E2%98%85
656
657 [![★][dynamodb-store-image] dynamodb-store][dynamodb-store-url] A DynamoDB-based session store.
658
659 [dynamodb-store-url]: https://www.npmjs.com/package/dynamodb-store
660 [dynamodb-store-image]: https://badgen.net/github/stars/rafaelrpinto/dynamodb-store?label=%E2%98%85
661
662 [![★][express-etcd-image] express-etcd][express-etcd-url] An [etcd](https://github.com/stianeikeland/node-etcd) based session store.
663
664 [express-etcd-url]: https://www.npmjs.com/package/express-etcd
665 [express-etcd-image]: https://badgen.net/github/stars/gildean/express-etcd?label=%E2%98%85
666
667 [![★][express-mysql-session-image] express-mysql-session][express-mysql-session-url] A session store using native
668 [MySQL](https://www.mysql.com/) via the [node-mysql](https://github.com/felixge/node-mysql) module.
669
670 [express-mysql-session-url]: https://www.npmjs.com/package/express-mysql-session
671 [express-mysql-session-image]: https://badgen.net/github/stars/chill117/express-mysql-session?label=%E2%98%85
672
673 [![★][express-nedb-session-image] express-nedb-session][express-nedb-session-url] A NeDB-based session store.
674
675 [express-nedb-session-url]: https://www.npmjs.com/package/express-nedb-session
676 [express-nedb-session-image]: https://badgen.net/github/stars/louischatriot/express-nedb-session?label=%E2%98%85
677
678 [![★][express-oracle-session-image] express-oracle-session][express-oracle-session-url] A session store using native
679 [oracle](https://www.oracle.com/) via the [node-oracledb](https://www.npmjs.com/package/oracledb) module.
680
681 [express-oracle-session-url]: https://www.npmjs.com/package/express-oracle-session
682 [express-oracle-session-image]: https://badgen.net/github/stars/slumber86/express-oracle-session?label=%E2%98%85
683
684 [![★][express-session-cache-manager-image] express-session-cache-manager][express-session-cache-manager-url]
685 A store that implements [cache-manager](https://www.npmjs.com/package/cache-manager), which supports
686 a [variety of storage types](https://www.npmjs.com/package/cache-manager#store-engines).
687
688 [express-session-cache-manager-url]: https://www.npmjs.com/package/express-session-cache-manager
689 [express-session-cache-manager-image]: https://badgen.net/github/stars/theogravity/express-session-cache-manager?label=%E2%98%85
690
691 [![★][express-session-etcd3-image] express-session-etcd3][express-session-etcd3-url] An [etcd3](https://github.com/mixer/etcd3) based session store.
692
693 [express-session-etcd3-url]: https://www.npmjs.com/package/express-session-etcd3
694 [express-session-etcd3-image]: https://badgen.net/github/stars/willgm/express-session-etcd3?label=%E2%98%85
695
696 [![★][express-session-level-image] express-session-level][express-session-level-url] A [LevelDB](https://github.com/Level/levelup) based session store.
697
698 [express-session-level-url]: https://www.npmjs.com/package/express-session-level
699 [express-session-level-image]: https://badgen.net/github/stars/tgohn/express-session-level?label=%E2%98%85
700
701 [![★][express-session-rsdb-image] express-session-rsdb][express-session-rsdb-url] Session store based on Rocket-Store: A very simple, super fast and yet powerfull, flat file database.
702
703 [express-session-rsdb-url]: https://www.npmjs.com/package/express-session-rsdb
704 [express-session-rsdb-image]: https://badgen.net/github/stars/paragi/express-session-rsdb?label=%E2%98%85
705
706 [![★][express-sessions-image] express-sessions][express-sessions-url] A session store supporting both MongoDB and Redis.
707
708 [express-sessions-url]: https://www.npmjs.com/package/express-sessions
709 [express-sessions-image]: https://badgen.net/github/stars/konteck/express-sessions?label=%E2%98%85
710
711 [![★][firestore-store-image] firestore-store][firestore-store-url] A [Firestore](https://github.com/hendrysadrak/firestore-store)-based session store.
712
713 [firestore-store-url]: https://www.npmjs.com/package/firestore-store
714 [firestore-store-image]: https://badgen.net/github/stars/hendrysadrak/firestore-store?label=%E2%98%85
715
716 [![★][fortune-session-image] fortune-session][fortune-session-url] A [Fortune.js](https://github.com/fortunejs/fortune)
717 based session store. Supports all backends supported by Fortune (MongoDB, Redis, Postgres, NeDB).
718
719 [fortune-session-url]: https://www.npmjs.com/package/fortune-session
720 [fortune-session-image]: https://badgen.net/github/stars/aliceklipper/fortune-session?label=%E2%98%85
721
722 [![★][hazelcast-store-image] hazelcast-store][hazelcast-store-url] A Hazelcast-based session store built on the [Hazelcast Node Client](https://www.npmjs.com/package/hazelcast-client).
723
724 [hazelcast-store-url]: https://www.npmjs.com/package/hazelcast-store
725 [hazelcast-store-image]: https://badgen.net/github/stars/jackspaniel/hazelcast-store?label=%E2%98%85
726
727 [![★][level-session-store-image] level-session-store][level-session-store-url] A LevelDB-based session store.
728
729 [level-session-store-url]: https://www.npmjs.com/package/level-session-store
730 [level-session-store-image]: https://badgen.net/github/stars/toddself/level-session-store?label=%E2%98%85
731
732 [![★][lowdb-session-store-image] lowdb-session-store][lowdb-session-store-url] A [lowdb](https://www.npmjs.com/package/lowdb)-based session store.
733
734 [lowdb-session-store-url]: https://www.npmjs.com/package/lowdb-session-store
735 [lowdb-session-store-image]: https://badgen.net/github/stars/fhellwig/lowdb-session-store?label=%E2%98%85
736
737 [![★][medea-session-store-image] medea-session-store][medea-session-store-url] A Medea-based session store.
738
739 [medea-session-store-url]: https://www.npmjs.com/package/medea-session-store
740 [medea-session-store-image]: https://badgen.net/github/stars/BenjaminVadant/medea-session-store?label=%E2%98%85
741
742 [![★][memorystore-image] memorystore][memorystore-url] A memory session store made for production.
743
744 [memorystore-url]: https://www.npmjs.com/package/memorystore
745 [memorystore-image]: https://badgen.net/github/stars/roccomuso/memorystore?label=%E2%98%85
746
747 [![★][mssql-session-store-image] mssql-session-store][mssql-session-store-url] A SQL Server-based session store.
748
749 [mssql-session-store-url]: https://www.npmjs.com/package/mssql-session-store
750 [mssql-session-store-image]: https://badgen.net/github/stars/jwathen/mssql-session-store?label=%E2%98%85
751
752 [![★][nedb-session-store-image] nedb-session-store][nedb-session-store-url] An alternate NeDB-based (either in-memory or file-persisted) session store.
753
754 [nedb-session-store-url]: https://www.npmjs.com/package/nedb-session-store
755 [nedb-session-store-image]: https://badgen.net/github/stars/JamesMGreene/nedb-session-store?label=%E2%98%85
756
757 [![★][restsession-image] restsession][restsession-url] Store sessions utilizing a RESTful API
758
759 [restsession-url]: https://www.npmjs.com/package/restsession
760 [restsession-image]: https://badgen.net/github/stars/jankal/restsession?label=%E2%98%85
761
762 [![★][sequelstore-connect-image] sequelstore-connect][sequelstore-connect-url] A session store using [Sequelize.js](http://sequelizejs.com/).
763
764 [sequelstore-connect-url]: https://www.npmjs.com/package/sequelstore-connect
765 [sequelstore-connect-image]: https://badgen.net/github/stars/MattMcFarland/sequelstore-connect?label=%E2%98%85
766
767 [![★][session-file-store-image] session-file-store][session-file-store-url] A file system-based session store.
768
769 [session-file-store-url]: https://www.npmjs.com/package/session-file-store
770 [session-file-store-image]: https://badgen.net/github/stars/valery-barysok/session-file-store?label=%E2%98%85
771
772 [![★][session-pouchdb-store-image] session-pouchdb-store][session-pouchdb-store-url] Session store for PouchDB / CouchDB. Accepts embedded, custom, or remote PouchDB instance and realtime synchronization.
773
774 [session-pouchdb-store-url]: https://www.npmjs.com/package/session-pouchdb-store
775 [session-pouchdb-store-image]: https://badgen.net/github/stars/solzimer/session-pouchdb-store?label=%E2%98%85
776
777 [![★][session-rethinkdb-image] session-rethinkdb][session-rethinkdb-url] A [RethinkDB](http://rethinkdb.com/)-based session store.
778
779 [session-rethinkdb-url]: https://www.npmjs.com/package/session-rethinkdb
780 [session-rethinkdb-image]: https://badgen.net/github/stars/llambda/session-rethinkdb?label=%E2%98%85
781
782 [![★][sessionstore-image] sessionstore][sessionstore-url] A session store that works with various databases.
783
784 [sessionstore-url]: https://www.npmjs.com/package/sessionstore
785 [sessionstore-image]: https://badgen.net/github/stars/adrai/sessionstore?label=%E2%98%85
786
787 [![★][tch-nedb-session-image] tch-nedb-session][tch-nedb-session-url] A file system session store based on NeDB.
788
789 [tch-nedb-session-url]: https://www.npmjs.com/package/tch-nedb-session
790 [tch-nedb-session-image]: https://badgen.net/github/stars/tomaschyly/NeDBSession?label=%E2%98%85
791
792 ## Example
793
794 A simple example using `express-session` to store page views for a user.
795
796 ```js
797 var express = require('express')
798 var parseurl = require('parseurl')
799 var session = require('express-session')
800
801 var app = express()
802
803 app.use(session({
804   secret: 'keyboard cat',
805   resave: false,
806   saveUninitialized: true
807 }))
808
809 app.use(function (req, res, next) {
810   if (!req.session.views) {
811     req.session.views = {}
812   }
813
814   // get the url pathname
815   var pathname = parseurl(req).pathname
816
817   // count the views
818   req.session.views[pathname] = (req.session.views[pathname] || 0) + 1
819
820   next()
821 })
822
823 app.get('/foo', function (req, res, next) {
824   res.send('you viewed this page ' + req.session.views['/foo'] + ' times')
825 })
826
827 app.get('/bar', function (req, res, next) {
828   res.send('you viewed this page ' + req.session.views['/bar'] + ' times')
829 })
830 ```
831
832 ## Debugging
833
834 This module uses the [debug](https://www.npmjs.com/package/debug) module
835 internally to log information about session operations.
836
837 To see all the internal logs, set the `DEBUG` environment variable to
838 `express-session` when launching your app (`npm start`, in this example):
839
840 ```sh
841 $ DEBUG=express-session npm start
842 ```
843
844 On Windows, use the corresponding command;
845
846 ```sh
847 > set DEBUG=express-session & npm start
848 ```
849
850 ## License
851
852 [MIT](LICENSE)
853
854 [rfc-6265bis-03-4.1.2.7]: https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7
855 [coveralls-image]: https://badgen.net/coveralls/c/github/expressjs/session/master
856 [coveralls-url]: https://coveralls.io/r/expressjs/session?branch=master
857 [node-url]: https://nodejs.org/en/download
858 [npm-downloads-image]: https://badgen.net/npm/dm/express-session
859 [npm-url]: https://npmjs.org/package/express-session
860 [npm-version-image]: https://badgen.net/npm/v/express-session
861 [travis-image]: https://badgen.net/travis/expressjs/session/master
862 [travis-url]: https://travis-ci.org/expressjs/session