Cron job versus Interval/Timeout
As you know, there are native JavaScript functions such as setInterval()
or setTimeout()
, which can run certain tasks periodically. But the main reason that they are not practical here is their limited lifespan. In other words, their life depends on the JavaScript host (mostly browsers) that executes them. Kill the browser process and they are long dead. This is not ideal, because we need a reliable process that runs in the background - possibly forever - and gathers news and sends emails without requiring to leave a browser window open 24/7.
For that reason, we need something on the system level and Cron jobs sound like a perfect choice for this matter. System administrators have been using them for decades and all we need is to run a command with a bunch of parameters inside a terminal window. With this solution, we can achieve our goal in three steps:
- First we need to generate a .js file so we can call it from the command line. We can continue creating...