title: Count the number of files in a directory using JavaScript/nodejs?
body: <p>How can I count the number of files in a directory using <code>nodejs</code> with just plain JavaScript or packages? I want to do something like this:</p>
  
  <p><a href="https://stackoverflow.com/questions/2632205/count-the-number-of-files-in-a-directory-using-python">How to count the number of files in a directory using Python</a></p>
  
  <p>Or in bash script I'd do this:</p>
  
  <pre><code>getLength() {
    DIRLENGTH=1
    until [ ! -d "DIR-$((DIRLENGTH+1))"  ]; do
      DIRLENGTH=$((DIRLENGTH+1))
    done
  }
  </code></pre>