visionmedia/express — Issue #950: sessions bug
Author: napa3um
Created: 2012-01-05 07:21:43+00:00
State: open

******** Operations in terminal:

[napa3um@hive Workspace]$ mkdir express-test
[napa3um@hive Workspace]$ cd express-test/
[napa3um@hive express-test]$ node -v
v0.6.6
[napa3um@hive express-test]$ npm -v
1.1.0-beta-4
[napa3um@hive express-test]$ npm install express
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-2.5.4.tgz
npm http 200 https://registry.npmjs.org/express/-/express-2.5.4.tgz
npm http GET https://registry.npmjs.org/mkdirp/0.0.7
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/mkdirp/0.0.7
npm http 304 https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/formidable
npm http 304 https://registry.npmjs.org/formidable
express@2.5.4 ./node_modules/express
├── mime@1.2.4
├── mkdirp@0.0.7
├── qs@0.4.0
└── connect@1.8.5

[napa3um@hive express-test]$ ./node_modules/.bin/express .
destination is not empty, continue? y

create : .
create : ./package.json
create : ./app.js
create : ./public
create : ./routes
create : ./routes/index.js
create : ./views
create : ./views/layout.jade
create : ./views/index.jade
create : ./public/javascripts
create : ./public/images
create : ./public/stylesheets
create : ./public/stylesheets/style.css

dont forget to install dependencies:
$ cd . && npm install

[napa3um@hive express-test]$ npm install -d
npm info it worked if it ends with ok
npm info using npm@1.1.0-beta-4
npm info using node@v0.6.6
npm info preinstall application-name@0.0.1
npm http GET https://registry.npmjs.org/jade
npm http 304 https://registry.npmjs.org/jade
npm info into /home/napa3um/Workspace/express-test jade@0.20.0
npm info installOne jade@0.20.0
npm info unbuild /home/napa3um/Workspace/express-test/node_modules/jade
npm info preinstall jade@0.20.0
npm http GET https://registry.npmjs.org/commander
npm http GET https://registry.npmjs.org/mkdirp
npm http 304 https://registry.npmjs.org/commander
npm http 304 https://registry.npmjs.org/mkdirp
npm info into /home/napa3um/Workspace/express-test/node_modules/jade commander@0.2.1
npm info into /home/napa3um/Workspace/express-test/node_modules/jade mkdirp@0.2.1
npm info installOne commander@0.2.1
npm info installOne mkdirp@0.2.1
npm info unbuild /home/napa3um/Workspace/express-test/node_modules/jade/node_modules/commander
npm info unbuild /home/napa3um/Workspace/express-test/node_modules/jade/node_modules/mkdirp
npm info preinstall mkdirp@0.2.1
npm info build /home/napa3um/Workspace/express-test/node_modules/jade/node_modules/mkdirp
npm info linkStuff mkdirp@0.2.1
npm info install mkdirp@0.2.1
npm info postinstall mkdirp@0.2.1
npm info preinstall commander@0.2.1
npm info build /home/napa3um/Workspace/express-test/node_modules/jade/node_modules/commander
npm info linkStuff commander@0.2.1
npm info install commander@0.2.1
npm info postinstall commander@0.2.1
npm info build /home/napa3um/Workspace/express-test/node_modules/jade
npm info linkStuff jade@0.20.0
npm info install jade@0.20.0
npm info postinstall jade@0.20.0
npm info build /home/napa3um/Workspace/express-test
npm info linkStuff application-name@0.0.1
npm info install application-name@0.0.1
npm info postinstall application-name@0.0.1
jade@0.20.0 ./node_modules/jade
├── mkdirp@0.2.1
└── commander@0.2.1
npm info ok

******** Change index.js:

exports.index = function(req, res){

if (!('i' in req.session))
req.session.i = 0;
req.session.i++;
console.log(req.session.i);

res.render('index', { title: 'Express' })
};

******** Operations in terminal (and browser in http://localhost:3000/):

[napa3um@hive express-test]$ node app.js
Express server listening on port 3000 in development mode
TypeError: Cannot use 'in' operator to search for 'i' in undefined
at String.IN (native)
at /home/napa3um/Workspace/express-test/routes/index.js:8:18
at callbacks (/home/napa3um/Workspace/express-test/node_modules/express/lib/router/index.js:272:11)
at param (/home/napa3um/Workspace/express-test/node_modules/express/lib/router/index.js:246:11)
at pass (/home/napa3um/Workspace/express-test/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/home/napa3um/Workspace/express-test/node_modules/express/lib/router/index.js:280:4)
at Object.handle (/home/napa3um/Workspace/express-test/node_modules/express/lib/router/index.js:45:10)
at next (/home/napa3um/Workspace/express-test/node_modules/express/node_modules/connect/lib/http.js:203:15)
at Object.methodOverride [as handle] (/home/napa3um/Workspace/express-test/node_modules/express/node_modules/connect/lib/middleware/methodOverride.js:35:5)
at next (/home/napa3um/Workspace/express-test/node_modules/express/node_modules/connect/lib/http.js:203:15)