Home > Software engineering >  Should I keep my prompt always open to run the scheduled node.js script?
Should I keep my prompt always open to run the scheduled node.js script?

Time:09-27

In a previous question i asked about how to run index.js at an specific time, at first I thought all my project files would go to the web host, but i was told the index.js should be run on a server.

I googled and found it. i installed node-schedule, i wrapped my async puppeteer in a function then set schedule.scheduleJob( '44 02 * * *', myFunction) and put my index.html with js/css on a xampp and used ngrok. all right, im very happy my app is live.

now i need to know if i have to leave my prompt live so the scheduler will run always.

i mean, is there a better way to do it?

CodePudding user response:

Are you saving the results in a DB or serving via REST api? I would try separate the scraper in a own job.

If not I guess you need to keep it open

CodePudding user response:

You have a few options:

  • systemd timers (.timer files), a modern version of cron / at
  • cron jobs (for repeated jobs)
  • at jobs (for once-off jobs)
  • screen. SSH into the host, run screen, run your command (node index.js), press Ctrl D to disconnect. You can then log out of the host and the command keeps running. Log back in and run screen -r to reconnect and see the output of the command.
  • Related