title: Node.js check if path is directory error
body: <p>I'm trying to use <a href="https://stackoverflow.com/a/15630832/2908941">this answer</a> to allow me to check if a given file path is a directory, however I get the following error:</p>
  
  <pre><code>fs.js:679
    return binding.lstat(pathModule._makeLong(path));
                   ^
  Error: ENOENT, no such file or directory '.DS_Store'
      at Object.fs.lstatSync (fs.js:679:18)
  </code></pre>
  
  <p>I figured that maybe it couldn't handle hidden files well, so, after failing to find a more elegant solution, I checked if the first character in the file name was a '.'. However, the program then crashed on another file:</p>
  
  <pre><code>fs.js:679
    return binding.lstat(pathModule._makeLong(path));
                   ^
  Error: ENOENT, no such file or directory 'README.md'
      at Object.fs.lstatSync (fs.js:679:18)
  </code></pre>
  
  <p>Why does <code>fs.lstatSync()</code> seem to error for such common files, and how can I make it work (correctly evaluate if the given path is a directory)?</p>