title: Writing a big JSON file slows whole program - and express app
body: <p>I have a very large JSON file that updates sometimes, so I pack it and save it every few minutes with <code>jsonpack</code>.</p>
  <p>The problem is, this process slows the entire website (<code>express</code>) to a halt while it does so. It often takes around 30 seconds before it serves traffic again.</p>
  <p>Here is the snippet that does the saving:</p>
  <pre><code>setInterval(() =&gt; {
    //if(db.sites.length &gt; 250000){
    if(db.sites.length &gt; siteCap){
      canqueue = false
    }else{
      console.log(`${db.sites.length} stored, (${noCrawl.length} noCrawl)`)
    }
    fs.writeFile(&quot;./db.txt&quot;,jsonpack.pack(db),()=&gt;{console.log(&quot;done!&quot;)})
  }, 600000);
  </code></pre>
  <p>Hopefully, there is a solution to it slowing down this much.
  The full code is on this GitHub repo if needed: <a href="https://github.com/codingMASTER398/Cheesgle" rel="nofollow noreferrer">https://github.com/codingMASTER398/Cheesgle</a> (snippet is at line 203 at the moment)</p>