Created
March 29, 2016 15:43
-
-
Save sboehler/f1d1f99bda1d4ee41c50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var path = require('path'); | |
| var cookieParser = require('cookie-parser'); | |
| var bodyParser = require('body-parser'); | |
| var session = require('express-session'); | |
| var app = express(); | |
| // Use the session middleware | |
| app.use(session({ | |
| secret: 'keyboard cat', | |
| rolling: true, | |
| saveUninitialized: true, | |
| resave: false, | |
| cookie: { maxAge: 10000 } | |
| })); | |
| // Access the session as req.session | |
| app.get('/', function(req, res, next) { | |
| var sess = req.session | |
| res.setHeader('Content-Type', 'text/html'); | |
| res.write('<p>views: ' + sess.views + '</p>'); | |
| res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's</p>'); | |
| res.end(); | |
| }); | |
| app.listen(3000, () => console.log('up and running')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment