Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!