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]
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):
15 $ npm install express-session
21 var session = require('express-session')
26 Create a session middleware with the given `options`.
28 **Note** Session data is _not_ saved in the cookie itself, just the session ID.
29 Session data is stored server-side.
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`.
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
41 For a list of stores, see [compatible session stores](#compatible-session-stores).
45 `express-session` accepts these properties in the options object.
49 Settings object for the session ID cookie. The default value is
50 `{ path: '/', httpOnly: true, secure: false, maxAge: null }`.
52 The following are options that can be set in this object.
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
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
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.
70 **Note** The `expires` option should not be set directly; instead only use the `maxAge`
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`
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`.
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.
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.
94 Specifies the value for the `Path` `Set-Cookie`. By default, this is set to `'/'`, which
95 is the root path of the domain.
99 Specifies the `boolean` or `string` to be the value for the `SameSite` `Set-Cookie` attribute.
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.
107 More information about the different enforcement levels can be found in
108 [the specification][rfc-6265bis-03-4.1.2.7].
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.
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.
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
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:
131 app.set('trust proxy', 1) // trust first proxy
133 secret: 'keyboard cat',
135 saveUninitialized: true,
136 cookie: { secure: true }
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:
146 secret: 'keyboard cat',
150 if (app.get('env') === 'production') {
151 app.set('trust proxy', 1) // trust first proxy
152 sess.cookie.secure = true // serve secure cookies
155 app.use(session(sess))
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.
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
172 The default value is a function which uses the `uid-safe` library to generate IDs.
174 **NOTE** be careful to generate unique IDs so your sessions do not conflict.
178 genid: function(req) {
179 return genuuid() // use UUIDs for session IDs
181 secret: 'keyboard cat'
187 The name of the session ID cookie to set in the response (and read from in the
190 The default value is `'connect.sid'`.
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.
199 Trust the reverse proxy when setting secure cookies (via the "X-Forwarded-Proto"
202 The default value is `undefined`.
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
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).
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
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`.
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
235 The default value is `false`.
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.
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.
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.
250 ##### saveUninitialized
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
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.
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*
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.
279 The session store instance, defaults to a new `MemoryStore` instance.
283 Control the result of unsetting `req.session` (through `delete`, setting to `null`,
286 The default value is `'keep'`.
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.
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:
299 // Use the session middleware
300 app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))
302 // Access the session as req.session
303 app.get('/', function(req, res, next) {
304 if (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>')
311 req.session.views = 1
312 res.end('welcome to the session demo. refresh!')
317 #### Session.regenerate(callback)
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.
324 req.session.regenerate(function(err) {
325 // will have a new session here
329 #### Session.destroy(callback)
331 Destroys the session and will unset the `req.session` property.
332 Once complete, the `callback` will be invoked.
335 req.session.destroy(function(err) {
336 // cannot access session here
340 #### Session.reload(callback)
342 Reloads the session data from the store and re-populates the
343 `req.session` object. Once complete, the `callback` will be invoked.
346 req.session.reload(function(err) {
351 #### Session.save(callback)
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).
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.
362 There are some cases where it is useful to call this method, for example,
363 redirects, long-lived requests or in WebSockets.
366 req.session.save(function(err) {
373 Updates the `.maxAge` property. Typically this is
374 not necessary to call, as the session middleware does this for you.
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`
383 ### req.session.cookie
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.
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
399 req.session.cookie.expires = new Date(Date.now() + hour)
400 req.session.cookie.maxAge = hour
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.
409 req.session.cookie.maxAge // => 30000
412 #### Cookie.originalMaxAge
414 The `req.session.cookie.originalMaxAge` property returns the original
415 `maxAge` (time-to-live), in milliseconds, of the session cookie.
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
423 ## Session Store Implementation
425 Every session store _must_ be an `EventEmitter` and implement specific
426 methods. The following methods are the list of **required**, **recommended**,
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
432 * Optional methods are ones this module does not call at all, but helps
433 present uniform stores to users.
435 For an example implementation view the [connect-redis](http://github.com/visionmedia/connect-redis) repo.
437 ### store.all(callback)
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)`.
444 ### store.destroy(sid, callback)
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.
452 ### store.clear(callback)
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.
459 ### store.length(callback)
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)`.
466 ### store.get(sid, callback)
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)`.
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)`.
477 ### store.set(sid, session, callback)
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.
485 ### store.touch(sid, session, callback)
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.
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.
497 ## Compatible Session Stores
499 The following modules implement a session store that is compatible with this
500 module. Please make a PR to add additional modules :)
502 [![★][aerospike-session-store-image] aerospike-session-store][aerospike-session-store-url] A session store using [Aerospike](http://www.aerospike.com/).
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
507 [![★][cassandra-store-image] cassandra-store][cassandra-store-url] An Apache Cassandra-based session store.
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
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).
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
519 [![★][connect-arango-image] connect-arango][connect-arango-url] An ArangoDB-based session store.
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
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.
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
529 [![★][connect-cloudant-store-image] connect-cloudant-store][connect-cloudant-store-url] An [IBM Cloudant](https://cloudant.com/)-based session store.
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
534 [![★][connect-couchbase-image] connect-couchbase][connect-couchbase-url] A [couchbase](http://www.couchbase.com/)-based session store.
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
539 [![★][connect-datacache-image] connect-datacache][connect-datacache-url] An [IBM Bluemix Data Cache](http://www.ibm.com/cloud-computing/bluemix/)-based session store.
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
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.
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
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.
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
554 [![★][connect-dynamodb-image] connect-dynamodb][connect-dynamodb-url] A DynamoDB-based session store.
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
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.
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
564 [![★][connect-hazelcast-image] connect-hazelcast][connect-hazelcast-url] Hazelcast session store for Connect and Express.
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
569 [![★][connect-loki-image] connect-loki][connect-loki-url] A Loki.js-based session store.
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
574 [![★][connect-memcached-image] connect-memcached][connect-memcached-url] A memcached-based session store.
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
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.
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
585 [![★][connect-ml-image] connect-ml][connect-ml-url] A MarkLogic Server-based session store.
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
590 [![★][connect-monetdb-image] connect-monetdb][connect-monetdb-url] A MonetDB-based session store.
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
595 [![★][connect-mongo-image] connect-mongo][connect-mongo-url] A MongoDB-based session store.
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
600 [![★][connect-mongodb-session-image] connect-mongodb-session][connect-mongodb-session-url] Lightweight MongoDB-based session store built and maintained by MongoDB.
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
605 [![★][connect-mssql-image] connect-mssql][connect-mssql-url] A SQL Server-based session store.
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
610 [![★][connect-pg-simple-image] connect-pg-simple][connect-pg-simple-url] A PostgreSQL-based session store.
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
615 [![★][connect-redis-image] connect-redis][connect-redis-url] A Redis-based session store.
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
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/)
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
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.
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
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.
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
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.
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
642 [![★][connect-typeorm-image] connect-typeorm][connect-typeorm-url] A [TypeORM](https://github.com/typeorm/typeorm)-based session store.
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
647 [![★][couchdb-expression-image] couchdb-expression][couchdb-expression-url] A [CouchDB](https://couchdb.apache.org/)-based session store.
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
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.
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
657 [![★][dynamodb-store-image] dynamodb-store][dynamodb-store-url] A DynamoDB-based session store.
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
662 [![★][express-etcd-image] express-etcd][express-etcd-url] An [etcd](https://github.com/stianeikeland/node-etcd) based session store.
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
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.
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
673 [![★][express-nedb-session-image] express-nedb-session][express-nedb-session-url] A NeDB-based session store.
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
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.
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
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).
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
691 [![★][express-session-etcd3-image] express-session-etcd3][express-session-etcd3-url] An [etcd3](https://github.com/mixer/etcd3) based session store.
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
696 [![★][express-session-level-image] express-session-level][express-session-level-url] A [LevelDB](https://github.com/Level/levelup) based session store.
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
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.
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
706 [![★][express-sessions-image] express-sessions][express-sessions-url] A session store supporting both MongoDB and Redis.
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
711 [![★][firestore-store-image] firestore-store][firestore-store-url] A [Firestore](https://github.com/hendrysadrak/firestore-store)-based session store.
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
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).
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
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).
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
727 [![★][level-session-store-image] level-session-store][level-session-store-url] A LevelDB-based session store.
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
732 [![★][lowdb-session-store-image] lowdb-session-store][lowdb-session-store-url] A [lowdb](https://www.npmjs.com/package/lowdb)-based session store.
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
737 [![★][medea-session-store-image] medea-session-store][medea-session-store-url] A Medea-based session store.
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
742 [![★][memorystore-image] memorystore][memorystore-url] A memory session store made for production.
744 [memorystore-url]: https://www.npmjs.com/package/memorystore
745 [memorystore-image]: https://badgen.net/github/stars/roccomuso/memorystore?label=%E2%98%85
747 [![★][mssql-session-store-image] mssql-session-store][mssql-session-store-url] A SQL Server-based session store.
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
752 [![★][nedb-session-store-image] nedb-session-store][nedb-session-store-url] An alternate NeDB-based (either in-memory or file-persisted) session store.
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
757 [![★][restsession-image] restsession][restsession-url] Store sessions utilizing a RESTful API
759 [restsession-url]: https://www.npmjs.com/package/restsession
760 [restsession-image]: https://badgen.net/github/stars/jankal/restsession?label=%E2%98%85
762 [![★][sequelstore-connect-image] sequelstore-connect][sequelstore-connect-url] A session store using [Sequelize.js](http://sequelizejs.com/).
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
767 [![★][session-file-store-image] session-file-store][session-file-store-url] A file system-based session store.
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
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.
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
777 [![★][session-rethinkdb-image] session-rethinkdb][session-rethinkdb-url] A [RethinkDB](http://rethinkdb.com/)-based session store.
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
782 [![★][sessionstore-image] sessionstore][sessionstore-url] A session store that works with various databases.
784 [sessionstore-url]: https://www.npmjs.com/package/sessionstore
785 [sessionstore-image]: https://badgen.net/github/stars/adrai/sessionstore?label=%E2%98%85
787 [![★][tch-nedb-session-image] tch-nedb-session][tch-nedb-session-url] A file system session store based on NeDB.
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
794 A simple example using `express-session` to store page views for a user.
797 var express = require('express')
798 var parseurl = require('parseurl')
799 var session = require('express-session')
804 secret: 'keyboard cat',
806 saveUninitialized: true
809 app.use(function (req, res, next) {
810 if (!req.session.views) {
811 req.session.views = {}
814 // get the url pathname
815 var pathname = parseurl(req).pathname
818 req.session.views[pathname] = (req.session.views[pathname] || 0) + 1
823 app.get('/foo', function (req, res, next) {
824 res.send('you viewed this page ' + req.session.views['/foo'] + ' times')
827 app.get('/bar', function (req, res, next) {
828 res.send('you viewed this page ' + req.session.views['/bar'] + ' times')
834 This module uses the [debug](https://www.npmjs.com/package/debug) module
835 internally to log information about session operations.
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):
841 $ DEBUG=express-session npm start
844 On Windows, use the corresponding command;
847 > set DEBUG=express-session & npm start
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