Storing consistent timer in mongodb

Lets say i have this timer in js:

 startTimer()
 
 
function startTimer(duration, display) {
 if (user_energy < 100) {
 setInterval(function () {
 minutes = parseInt(timer / 60, 10);
 seconds = parseInt(timer % 60, 10);

 minutes = minutes < 10 ? "0" + minutes : minutes;
 seconds = seconds < 10 ? "0" + seconds : seconds;

 display.textContent = minutes + ":" + seconds;

  if (--timer < 0) {
  timer = duration;           
   }
   }, 1000);
   }
   }
 
  if (user_energy < 100) {
  window.onload = function () {
  var fiveMinutes = 60 * 2.5,
  display = document.querySelector('#energytimer');
  startTimer(fiveMinutes, display);
   };
   }

How could i store this in the database so it stays consistent and wont restart after a page refresh?