index.js
This file
Path
examples/session/index.js
32 lines · 727 bytes · JavaScript
Last changed by
Merge branch 'examples'TJ Holowaychukbefore adoptionc492cde
History of this fileTake it
The walk stopped after 200 commits: lines older than 8ac3e80 point at it.
Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
line 1why, one step back1Merge branch 'examples'TJ Holowaychukbefore adoptionc492cde
lines 2–5why, one step back2// first:3// $ npm install redis4// $ redis-server5Merge branch 'master' of github.com:visionmedia/expressTJ Holowaychukbefore adoption8ac3e80
lines 6–32why, one step back6var express = require('../..');78var app = express();910app.use(express.logger('dev'));1112// Required by session() middleware13// pass the secret for signed cookies14// (required by session())15app.use(express.cookieParser('keyboard cat'));1617// Populates req.session18app.use(express.session());1920app.get('/', function(req, res){21 var body = '';22 if (req.session.views) {23 ++req.session.views;24 } else {25 req.session.views = 1;26 body += '<p>First time visiting? view this page in several browsers :)</p>';27 }28 res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');29});3031app.listen(3000);32console.log('Express app started on port 3000');