title: Scheduling Tasks in Node.js Using Timers instead of Scheduled Cron Jobs
body: <p>This is my objective:</p>
  
  <blockquote>
    <p>5 minutes after the last document update, I want to execute a one-time task</p>
  </blockquote>
  
  <p>So this is what the flow of actions will look like:</p>
  
  <ol>
  <li>User updates document - timer is started and counts down from 5 minutes</li>
  <li>If user updates the same document again and the previous timer (identified by the document._id) is running still, reset that timer back to 5 minutes and repeat countdown</li>
  <li>When timer has elapsed - the one time task is executed</li>
  </ol>
  
  <p>I have not done something like this before and I am at a loss at where to begin.</p>
  
  <p>I can hook into document changes easily using methods available in Mongoose (i.e. on save, do func to setup or reset timer)</p>
  
  <p>However, I cannot figure out the way to:</p>
  
  <ul>
  <li>create a timer that waits 5 minutes - then executes a task</li>
  <li>making the timer accessible so that I can reset the timer</li>
  <li>making the timer accessible so I can add extra variables which will be used in the funtion when timer has elapsed</li>
  </ul>
  
  <p>I've investigated Cron jobs but they seem to tasks that schedule at the same time everyday. </p>
  
  <p>I need a timer that delays a task, but also the ability to reset that timer, and add extra data to the timer.</p>
  
  <p>Any hints appreciated.</p>