UNPKG

fruitstand

Version:
47 lines (46 loc) 5.3 kB
{ "name": "express-session", "version": "1.0.3", "author": { "name": "TJ Holowaychuk", "email": "tj@vision-media.ca", "url": "http://tjholowaychuk.com" }, "main": "./index.js", "repository": { "type": "git", "url": "git://github.com/expressjs/session.git" }, "dependencies": { "utils-merge": "1.0.0", "cookie": "0.1.2", "cookie-signature": "1.0.3", "uid2": "0.0.3", "buffer-crc32": "0.2.1", "debug": "0.7.4" }, "devDependencies": { "mocha": "~1.17.0", "express": "4.0.0", "supertest": "0.9.0", "should": "3.1.2", "cookie-parser": "1.0.1" }, "scripts": { "test": "mocha --bail --ui bdd --reporter list -- test/*.js" }, "license": "MIT", "readme": "THIS REPOSITORY NEEDS A MAINTAINER. IF YOU'RE INTERESTED IN MAINTAINING THIS REPOSITORY, PLEASE LET US KNOW!\n\n# express-session\n\nSetup session store with the given `options`.\n\nSession data is _not_ saved in the cookie itself, however\ncookies are used, so we must use the [cookieParser()](cookieParser.html)\nmiddleware _before_ `session()`.\n\n## Example\n\n```js\nvar cookieParser = require('cookie-parser');\nvar session = require('express-session');\n\napp.use(cookieParser())\napp.use(session({ secret: 'keyboard cat', key: 'sid', cookie: { secure: true }}))\n```\n\n**Options**\n\n - `key` cookie name defaulting to `connect.sid`\n - `store` session store instance\n - `secret` session cookie is signed with this secret to prevent tampering\n - `cookie` session cookie settings, defaulting to `{ path: '/', httpOnly: true, maxAge: null }`\n - `proxy` trust the reverse proxy when setting secure cookies (via \"x-forwarded-proto\")\n\n**Cookie options**\n\nBy default `cookie.maxAge` is `null`, meaning no \"expires\" parameter is set\nso the cookie becomes a browser-session cookie. When the user closes the\nbrowser the cookie (and session) will be removed.\n\n## req.session\n\nTo store or access session data, simply use the request property `req.session`,\nwhich is (generally) serialized as JSON by the store, so nested objects\nare typically fine. For example below is a user-specific view counter:\n\n```js\napp.use(cookieParser())\napp.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }}))\n\napp.use(function(req, res, next){\n var sess = req.session;\n if (sess.views) {\n res.setHeader('Content-Type', 'text/html');\n res.write('<p>views: ' + sess.views + '</p>');\n res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>');\n res.end();\n sess.views++;\n } else {\n sess.views = 1;\n res.end('welcome to the session demo. refresh!');\n }\n})\n```\n\n## Session#regenerate()\n\nTo regenerate the session simply invoke the method, once complete\na new SID and `Session` instance will be initialized at `req.session`.\n\n```js\nreq.session.regenerate(function(err){\n // will have a new session here\n});\n```\n\n## Session#destroy()\n\nDestroys the session, removing `req.session`, will be re-generated next request.\n\n```js\nreq.session.destroy(function(err){\n // cannot access session here\n});\n```\n\n## Session#reload()\n\nReloads the session data.\n\n```js\nreq.session.reload(function(err){\n // session updated\n});\n```\n\n## Session#save()\n\nSave the session.\n\n```js\nreq.session.save(function(err){\n // session saved\n});\n```\n\n## Session#touch()\n\nUpdates the `.maxAge` property. Typically this is\nnot necessary to call, as the session middleware does this for you.\n\n## Session#cookie\n\nEach session has a unique cookie object accompany it. This allows\nyou to alter the session cookie per visitor. For example we can\nset `req.session.cookie.expires` to `false` to enable the cookie\nto remain for only the duration of the user-agent.\n\n## Session#maxAge\n\nAlternatively `req.session.cookie.maxAge` will return the time\nremaining in milliseconds, which we may also re-assign a new value\nto adjust the `.expires` property appropriately. The following\nare essentially equivalent\n\n```js\nvar hour = 3600000;\nreq.session.cookie.expires = new Date(Date.now() + hour);\nreq.session.cookie.maxAge = hour;\n```\n\nFor example when `maxAge` is set to `60000` (one minute), and 30 seconds\nhas elapsed it will return `30000` until the current request has completed,\nat which time `req.session.touch()` is called to reset `req.session.maxAge`\nto its original value.\n\n```js\nreq.session.cookie.maxAge;\n// => 30000\n```\n\n## Session Store Implementation\n\nEvery session store _must_ implement the following methods\n\n - `.get(sid, callback)`\n - `.set(sid, session, callback)`\n - `.destroy(sid, callback)`\n\nRecommended methods include, but are not limited to:\n\n - `.length(callback)`\n - `.clear(callback)`\n", "readmeFilename": "README.md", "description": "THIS REPOSITORY NEEDS A MAINTAINER. IF YOU'RE INTERESTED IN MAINTAINING THIS REPOSITORY, PLEASE LET US KNOW!", "bugs": { "url": "https://github.com/expressjs/session/issues" }, "homepage": "https://github.com/expressjs/session", "_id": "express-session@1.0.3", "dist": { "shasum": "7f328f7bce0bc8e62f9ebd4ffeed1d7e99c5e3ff" }, "_from": "express-session@", "_resolved": "https://registry.npmjs.org/express-session/-/express-session-1.0.3.tgz" }