title: Massive memory/RAM usage with Chokidar Node.js package from pre-existing files in directory being watched unnecessarily
body: <p>I'm using the Node.js package &quot;chokidar&quot; for this use case:</p>
  <ul>
  <li>I'm just watching a single directory on Linux, not recursively</li>
  <li>I only need it to watch for <code>add</code> events, for when files are atomically moved into the watched directory (they're moved from another directory on the same filesystem once all changes are done)</li>
  <li>I don't need it to look at pre-existing files in the dir at all, just watch for new ones since the app started</li>
  </ul>
  <h3>Problem:</h3>
  <ul>
  <li>When there is a large number of pre-existing files (like 80k) in the directory when I start my node.js app, Chokidar seems to put a watch on all of them, even though I don't care about watching existing files at all</li>
  <li>Initially this was hitting the kernel watch limit, but I've already solved that with:</li>
  </ul>
  <p>...</p>
  <pre><code>echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf &amp;&amp; sudo sysctl -p
  </code></pre>
  <ul>
  <li>The remaining issue is that all these pre-existing files are being watched, which uses a massive amount of RAM for no reason, as I don't need it watching those files at all.</li>
  <li>Is there any way to have Chokidar just entirely ignore all these pre-existing files, and do nothing but watch this single directory for <code>add</code> events for new files only?</li>
  <li>I know about increasing Node's RAM limits (which didn't work in this case anyway), but I feel like it shouldn't be using all this RAM in the first place, and I want it to be efficient on a small VPS.  I'd like to solve the RAM usage issue rather than just give it more RAM than it should need in the first place.</li>
  </ul>
  <h3>I'm using this code:</h3>
  <pre><code>chokidar.watch(&quot;/my-watched-dir&quot;, {
      ignoreInitial: true,
  })
  .on('add', (filepath) =&gt; {...}
  </code></pre>
  <p>I've also tried setting the <code>depth</code> option to 0 and 1 too.</p>
  <p>The memory usage climbs very high as soon as the app starts (even before the 1st new file appears triggering the <code>add</code> event for the first time).</p>
  <p>And there's no problem when the number of pre-existing files is smaller, so it's not an issue related to through-put of new files after the app starts.</p>