title: I keep getting an error in my Node.js server: "__dirname is not defined"
body: <p>I just started learning Node.js, and i'm stuck on trying to set up a middleware for static resources. When trying to do this i just keep getting a <strong>"__dirname not defined"</strong> error in my IDE. Although no errors show up in command line, i know it isn't working because my site still says <strong>"cannot GET /"</strong>. I also know that "__dirname" is recognised by my IDE because when i console.log(__dirname) it shows the directory in command line. But for some reason it wont work with the "app.use" function. </p>
  
  <pre><code>var express = require('express');
  var bodyParser = require('body-parser');
  var path = require('path');
  var app = express();
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({extended: false}));
  
  /*this won't work*/
  app.use(express.static(path.join(__dirname,'public')));
  
  
  app.listen(3000, function() {
             console.log(__dirname);
             })
  
  </code></pre>
  
  <p>i've also tried</p>
  
  <pre><code>app.use(express.static(__dirname + '/public'));
  
  </code></pre>
  
  <p>and that doesn't work either. </p>