Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
Continuously check whether or not a date has been expired

Here's our scenario:

We are using node w/ express for our web app and we need to create a background process that continuously checks the created date on multiple posts and when they expire. These expired dates are set by the user so the posts expire at different rates. When the date expires, our app should be triggering specific events.

We are considering using a "setInterval" but wasn't sure if this is the best long-term solution.

Is there a solution to have node continuously check whether or not a date has been expired? Upon expiring, the posts must trigger specific functions.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

There are two ways to do this:

1) use moment lib like this:

var date = moment("2013-03-24")
var now = moment();

if (now > date) {
   // date is past
} else {
   // date is future
}

2) use node-schedule like this:

var schedule = require('node-schedule');
var futureDate = new Date(new Date().getTime() + 60 * 60 * 24 * 1000); // This is 24 hours from *now*

var j = schedule.scheduleJob(futureDate, function(){
  console.log('Do your work here.');
});
over 4 years ago · Santiago Trujillo Denunciar

0

Im not sure about your code but if u can catch the event when the users post, the easy way would be

setTimeout(whateverYouHaveTodo, expireTimeInMilliseconds);

each time an event is triggered.

And if you need to cancel the timeouts in the future, what i do personally is put the timeouts in a json object with the key as a unique id which you could identify the event specifically

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda