https://github.com/montyanderson/trench-session
:date: Session middleware for Trench, using Redis.
https://github.com/montyanderson/trench-session
Last synced: 3 months ago
JSON representation
:date: Session middleware for Trench, using Redis.
- Host: GitHub
- URL: https://github.com/montyanderson/trench-session
- Owner: montyanderson
- License: mit
- Created: 2016-11-06T19:15:14.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-06T21:58:24.000Z (over 8 years ago)
- Last Synced: 2024-04-26T01:21:03.724Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trench-session
:date: Session middleware for [Trench](https://github.com/montyanderson/trench), using Redis.
## Usage
``` javascript
const Trench = require("trench");
const session = require("trench-session");const app = new Trench();
app.use(session({
app: "app"
}));app.get("/", (req, res) => {
if(!req.session.i) req.session.i = 0;
req.session.i++;res.end(req.session.i.toString());
});app.listen(8080);
```## API
### session([options])
Returns a middleware function to generate functions, then save them when `res.end()` is called.
#### options
##### app
Type: `string`
A name for the application, used so you can store multiple app's sessions in the same redis database, without possibility of interference.
##### expire
Type: `number`
Amount of seconds until the session expires, since last saved.
##### db
Type: `string`, `object`
Connection configuration, to be passed to `redis.createClient()`.
##### client
Type: `object`
A redis client, i.e. created by `redis.createClient()`.