1

I need to begin a cron job every time before I start my app. So in my package.json, I have the following scripts:

"prestart": "node ./scripts/pre-start",
"start": "node server.js",

This is my prestart script:

var CronJob = require('cron').CronJob

function preStart () {
  console.log('in the prestart function')
  const job = new CronJob('* * * * * *', function () {
    console.log('You will see this message every second')
  }, null, true, 'America/Los_Angeles')
  job.start()
}

preStart()
module.export = preStart

The issue is that I am getting stuck in my prestart (never get to run server.js from the start script)and all I wanted this to do is to run the cron job in the background as a I run my app.

How can I just set up my cron job and then move on to executing my app?

theJuls
  • 6,788
  • 14
  • 73
  • 160

0 Answers0