title: How to cancel jobs with node-schedule from a function
body: <p>I'm new to node.js and programming in general. I have a function in Node that gets called from the external main file of my server which calculates some dates and sets Jobs with node-schedule.</p>
  
  <p>The function runs every time a date is added. This means at the moment I have the problem that my jobs get set several times with the same value.</p>
  
  <p>I'm searching for a method to cancel my Jobs from outside this function, so I can later individually cancel specific jobs from the server's main file. This is the function that updates my Jobs.</p>
  
  <pre><code>exports.UpdateCron = function () {
    var date1 = new Date();
  
    var group1 = schedule.scheduleJob(date1, function(){
      console.log('group1 start');
    });
  };
  </code></pre>
  
  <p>This is the function I would like to call from my main file, but <code>group1</code> is not defined here. Can someone explain how I can access my Job <code>group1</code>, which is defined in the first function, from the second function? </p>
  
  <pre><code>exports.DeleteCron = function () {  
    group1.cancel();
  };
  </code></pre>
  
  <p>Both function are in the same file that includes node-schedule.</p>