title: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory. My script won't run on a server?
body: <p>I'm trying to run a script that makes a call to an API, and then sends the response to my mongodb database. The script uses setInterval() to run every 2 minutes, and it runs perfectly on my computer. Any errors that come up aren't fatal, and usually it will only cause one of the datapoints not to update on that run, but it will try again after 2 minutes and usually work this time.</p>
  <p>Anyway, when I host the nodejs app on a ubuntu server on aws ec2, I get error messages saying the heap is out of memory and within a few minutes of running, the data stops getting sent to my database. I've read online that you can increase the data allocation using a command like...</p>
  <pre><code>export NODE_OPTIONS=&quot;--max-old-space-size=5120&quot; #increase to 5gb
  </code></pre>
  <p>But how do I know how much to increase this by? Is there a way I can check how much memory my script needs to run? Or is there a way that I can host my script without this issue?</p>