title: Best way to keep an array of Node Cron jobs running in memory
body: <p>I need to keep an array of cron jobs in memory that run according to configuration specifics. Presently I am initializing the array of cron jobs a by getting the config data as records from a datastore. Then I traverse the records, create a cron job based on the information in each record. Once a cron job is created, it is stored in memory in a script level array. </p>
  
  <p>Here is the code that does the work.</p>
  
  <pre><code>const arrCronJobs = [];
  
  function populateEnvVarCronJobs() {
    console.log('populating crons');
    return dataHelper.getCronJobs()
      .then((results) =&gt; {
          // Task entities found.
          const jobs = results[0];
          jobs.forEach((job) =&gt; {
              const rtn = configCron(job);
              if (rtn) {
                  console.log(`adding job: ${rtn}`);
                  arrCronJobs.push(rtn);
              }
          });
          return arrCronJobs;
        })
        .catch(e =&gt; {
          console.log(e);
        });}
  
  //initialize the array of Cron jobs
  
  populateEnvVarCronJobs()
  .then(result =&gt; {
      console.log(result);
  });
  </code></pre>
  
  <p>The way I keep the whole thing running memory is to create an HTTP server that just keeps listening away.</p>
  
  <pre><code>const server = http.createServer( function(req, res) {
  /* Listener handler behavior...... */});
  
  server.listen(port);
  </code></pre>
  
  <p>My question is this: Is using a HTTP server the best way to keep the array of Cron jobs active in memory? Or is there some inherent risk that I am not seeing that dictates it will be better for me to take another approach?</p>
  
  <p>Thanks in advance. I look forward to reading thoughtful responses.</p>