title: Reaching html file in another subfolder express.js
body: <p>My folder hierarchy is as follows;</p>
  
  <p>public</p>
  
  <p>----index.html</p>
  
  <p>src</p>
  
  <p>----server.js</p>
  
  <p>when I run the code </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var app = express();
  var serv = require('http').Server(app);
  var net = require('net');
  var path = require('path');
  var port = 3000;
  
  app.use('/../public/', express.static(path.join(__dirname + '/../public/')));
  
  app.get('/', function(req,res){
      res.sendFile(__dirname + '/../public/index.html');
  });
  
  serv.listen(3000, function(){
      console.log('port ' + port + ' is started to being listened')
  });
  
  var io = require('socket.io')(serv,{});</code></pre>
  </div>
  </div>
  </p>
  
  <p>it returns forbidden error. How can I reach a file in another subfile? </p>
  
  <hr>
  
  <p>First of all, what I thought solved it actually didn't solve because I am running multiple projects to understand the basics and I was confused. But now everything is clear. What I am actually trying to do is trying to use express to divide everything to folders. As I didn't know much about http, I watched a lot of videos and finally, I figured it out after watching official introduction video of express on youtube.</p>
  
  <p>Here again what I am trying to accomplish;</p>
  
  <p>-localhost 
  --public
  ---index.html
  --src
  ---all server js files and other files that will concern game programming.</p>
  
  <p>As I was trying to reach above, I couldn't manage to do it. What did actually do the trick is;</p>
  
  <p>creating a variable that specifies 'public' directory which is another sub directory under localhost and use it as static which was simple from the beginning but as I didn't know much, I wasn't able to use it after studying few tutorials. As Michael mentioned above, I didn't even need following lines;</p>
  
  <pre><code>    app.get(publicDir, function(req, res){
           res.sendFile('index.html');
      })
  </code></pre>
  
  <p>All I did was;</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> 
   var publicDir = require('path').join(__dirname, '/../public');
  
   app.use(express.static(publicDir));</code></pre>
  </div>
  </div>
  </p>