How to run cron on your browser

For anyone that has ever done sysadmin in a Unix environment, cron is an indispensable tool. It gives you a single place where you can schedule jobs and tell them when to run in a simple format (see cron.guru). Thanks to the cron package in NPM, this functionality is available to JavaScript programs.

It's fairly straightforward to use if you are familiar with cron. You simply create an CronJob object constructed with a function and a string that tells when to run it. Since tools like browserify and webpack allow you to package up almost any node package as browser-ready code, it's trivial to set this up to run on a webpage.

Here's a quick script I made as an example. It's a clock that updates every 2 seconds and displays if it is Monday.

If you are developing something on the web where you need to display something to a user at a specific time or on a regular basis, this could be a major help.