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

91
Views
Trigger a function on the start of a new day in javascript

Everyday I need to trigger a function on the start of a new day. How do I do that in Javascript? I have a desktop application made on electron js. I am logging necessary logs in a log file. I am creating new log file every new day. But i need to zip log file every new day. So i want to trigger a function which is used for zipping log file on the start of a new day.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You have the following solutions, its depend on how your applications works

  • Your app is running on servers that you control -> Use cron

  • Your app is always online -> if its nodejs search for cronjob in npm packages, if its pure js work witch setTimeout/setInterval

  • Your app is reachable from outside -> Run a cronjob on a remote server to ping your application, or simply set a daily job on zappier/powerautomate to ping your application

  • Your app is not reachable from outside, not always online, and you dont want cron -> Manage logs when starting applications + use solution 1 when its oline

about 4 years ago · Juan Pablo Isaza Report

0

We have two options here:

  • Server Side [server is always up and running]
  • Clinet Side [web app needs to be executed/opened by an end user]

in server side, we have a very good package called node-schedule

but on the client side, we can use setTimeout and some normal time calculations to call a function after certain amount of time like given example.

const currDate = new Date();

// this will give the current time in ms
const currTime = currDate.getTime();

// increase the date by 1
currDate.setDate(currDate.getDate() + 1);

// set hours, mins, seconds to the 0 [as setHours can accepts (hours, mins, seconds, miliseconds), we can pass all the parameters at once]
currDate.setHours(0, 0, 0, 0);

// now currDate holds the time for midnight
const midnightTime = currDate.getTime();

// create a setTimeout function for the time difference
const diff = midnightTime - currTime;
console.log(`Code will be triggered after: ${diff}ms`);
setTimeout(() => {
  // your code goes here
}, diff);

about 4 years ago · Juan Pablo Isaza 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!