title: Serve static files and app.get conflict using Express.js
body: <p>I have this piece of code here:</p>
  
  <pre><code>var express = require('express')
    , http = require('http')
  
  var app = express();
  var server = app.listen(1344);
  var io = require('socket.io').listen(server);
  
  
  app.use(express.static(__dirname + '/public'));
  app.use(express.bodyParser());
  app.use(express.cookieParser());
  app.use(express.session({secret: 'secret'}));
  
  
  app.get('/', function(req, res){
      if(req.session){
          console.log(req.session);
      }
      console.log('ok');
  
  });
  </code></pre>
  
  <p>The code inside the <code>app.get()</code> callback is not being called. If I comment out the <code>app.use(express.static(__dirname + '/public'))</code> line, then the callaback works. I've tried changing the order, but its like a lottery! I would prefer to know whats going wrong here.</p>
  
  <p>I'm sure this have to do with lack of knowledge from my part on how the middleware is called. Can someone help me understand this problem? </p>
  
  <p>Basically I just want to perform some logic before the files are served and the index.html is load on the browser. By the way placing the <code>app.get()</code> before the <code>app.use(express.static())</code> line, does not did the trick!</p>