title: redirected to wrong html page when using express.static(__dirname) function in node.js with express
body: <p>I have a login page called <strong>login.html</strong> and an index page called <strong>index.html</strong>. I want to make a authentication and that only a connected user can access the index page. </p>
  
  <p>I did not implement the post method on the login HTML page. I have to manually send the login username and password by going on this url: </p>
  
  <pre><code>http://localhost:2222/?username=a&amp;password=b
  </code></pre>
  
  <p>Everything worked but I could not see my css, js and some other files in the index.html. To solve this problem I added this at the beginning of my code:</p>
  
  <pre><code>app.use(express.static(__dirname)); 
  </code></pre>
  
  <p>The problem is that now if I go to the localhost:2222 it shows the index.html file instead of the login.html file. Even if I use:</p>
  
  <pre><code>app.get('/', function (req, res) {
      res.redirect('/login');
  });  
  </code></pre>
  
  <p><strong>How does it come ? How can I solve this ?</strong></p>
  
  <p>The full code is: </p>
  
  <pre><code>var express = require("express");
  var port = process.env.PORT || 2222;
  var app = express();
  app.use(express.static(__dirname)); 
  var session = require('express-session')
  app.use(session({
      secret: 'keyboardcat',
      resave: true,
      saveUninitialized: true
  }));
  
  function checkAuth(req, res, next) {
      if (!req.session.user_id) {
          res.sendfile('login.html');
      } else {
          next();
      }
  }
  app.get('/', function (req, res) {
      res.redirect('/login');
  });  
  app.get("/login", function(req, res) {
      if (req.query.username === 'a' &amp;&amp; req.query.password === 'b') {
          req.session.user_id = req.query.username;
          res.redirect('index');
      } else {
          res.sendfile('login.html');
      }
  });
  app.get('/index', checkAuth, function(req, res){ 
      res.sendfile('index.html');
  });
  
  app.get('/logout', function (req, res) {
      delete req.session.user_id;
      res.redirect('/login');
  }); 
  </code></pre>
  
  <p>My file tree is as follow: index.html, login.html and server.js are in a folder called <em>server</em>. In this folder sever are also 4 folders: <em>JS</em>, <em>CSS</em>, <em>Images</em> and <em>Random</em>.</p>