skip to Main Content

I wanted to write a Api that calls every minute in my application.

I have tried the scheduler in firebase but in wanted to write it in my application.

please find the solution for this problem. that would be helpful.

thank you

2

Answers


  1. You can use a cron job and schedule it for every minute.

    const { CronJob } = require('cron');
    
    const Job = new CronJob({
      cronTime: '*/1 * * * *',
    
      callFn();
    });
    
    callFn() {
    // Code
    }
    
    Job.start();
    
    Login or Signup to reply.
  2. The node-cron library allows you to schedule tasks to run at specific intervals using cron syntax.

    npm install node-cron
    

    Example:

    const cron = require('node-cron');
    
    // Schedule a cron job to run a function every minute
    cron.schedule('* * * * *', () => {
      console.log('Cron job executed!');
    });
    

    * * * * * – This will generate a function every minute. You can customize it as per your requirements

    For the generate cron job string you can use this link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search