0

I have a function myFunction() which i want to execute once every day. I have used the package cron for the schedule part. Is there a way to module.export the return value of the function so that i can use it in other files.

// scheduler.js

const { CronJob } = require('cron');

const myFunction = async () => {
  const val = Math.floor(Math.random() * 100);
  return val + 1;
};

const job = new CronJob(
  '* * * * *',
  async () => {
    const cronValue = await myFunction();
    module.exports = cronValue;
  },
  null,
  true,
  'UTC'
);

job.start();


// otherFile.js

const cronValue = require('./scheduler');

console.log(cronValue);

But as i run otherFile.js i get just a {} as result.

can anyone help? Thanks in advance

0 Answers0