title: nodeJS - How to create and read session with express
body: <p>I want to create a user sessison when user enter the app. And read the session whenever needed. Here is my try</p>
  
  <pre><code>var io   = require('socket.io'),
      express = require('express');
      querystring = require('querystring');
  
  var app = express.createServer();
  app.get('/', function(req, res){
      var sessionVal = querystring.parse(req.url.substr(2));// sessionVal is an email for example: me@gmail.com
      app.use(express.cookieParser());
      app.use(express.session({ secret: sessionVal }));
  });
  var socket = io.listen(app);
  socket.on('connection', function(client) {
      client.on('message', function(message) {
          // message will be an object {text:'user text chat blah blah', email:'me@gmail.com'}
          // if the seesion stored, has the same value with message.email
          // then the message will be broadcasted
              socket.broadcast(message.text);
          // else will not broadcast  
      });
  });
  
  app.listen(4000);
  </code></pre>