title: TypeError: opendirSync is not a function
body: <p>I am writing an electron application and I want to use the opendirSync function of the fs module in order to count the number of files in a directory. However, I get the following error:</p>
  
  <pre><code>(node:12944) UnhandledPromiseRejectionWarning: TypeError: fs.opendirSync is not a function
      at DataImporter.CountFiles (C:\Users\v\Documents\Projects\Electron\asts\server\data_importer.js:18:8)
      at new DataImporter (C:\Users\v\Documents\Projects\Electron\asts\server\data_importer.js:5:26)
      at C:\Users\v\Documents\Projects\Electron\asts\main.js:32:19
  (node:12944) UnhandledPromiseRejectionWarning: TypeError: fs.opendir is not a function
      at DataImporter.CountFiles (C:\Users\v\Documents\Projects\Electron\asts\server\data_importer.js:18:8)
      at new DataImporter (C:\Users\v\Documents\Projects\Electron\asts\server\data_importer.js:5:26)
      at C:\Users\v\Documents\Projects\Electron\asts\main.js:32:19
  (node:12944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  (node:12944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  (node:12944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  (node:12944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>The code I am using is as follows:</p>
  
  <pre class="lang-js prettyprint-override"><code>let fs = require('fs');
  let path_mod = require('path');
  
  function CountFiles(path) {
      let dir_end = null;
      let count = 0;
      let directory = fs.opendirSync(path);
      while(1) {
        let ret = directory.readSync();
        if(!ret) {
          break;
        } else if(ret.isDirectory()) {
          console.log(path_mod.join(path, ret.name));        
          count += CountFiles(path_mod.join(path, ret.name));
        } else {
          count++;
        }
      }
      directory.closeSync();
      return count;
    }
  </code></pre>
  
  <p>Node Version: <code>12.6.0</code> </p>
  
  <p>Electron Version: <code>7.1.12</code> </p>
  
  <p>I cannot understand what causes this error and how to fix it. I know that the path is correct and that I have access to the target directory (since I also used the fs module to read a file from that directory).</p>
  
  <p>Thank you for you help.</p>