Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda