Is there some cron like library that would let me schedule some function to be ran at certain time (15:30 for example, not x hours from now etc)? If there isn't this kind of library how this should be implemented? Should I just set callback to be called every second and check the time and start jobs scheduled for the time or what?
This question is related to
scheduling
node.js
Both node-schedule and node-cron we can use to implement cron-based schedullers.
NOTE : for generating cron expressions , you can use this cron_maker
I am using kue: https://github.com/learnboost/kue . It is pretty nice.
The official features and my comments:
Edit:
later.js is a pretty good JavaScript "scheduler" library. Can run on Node.js or in a web browser.
You can use timexe
It's simple to use, light weight, has no dependencies, has an improved syntax over cron, with a resolution in milliseconds and works in the browser.
Install:
npm install timexe
Use:
var timexe = require('timexe');
var res = timexe("* * * 15 30", function(){ console.log("It's now 3:30 pm"); });
(I'm the author)
agenda is a Lightweight job scheduling for node. This will help you.
All these answers and noone has pointed to the most popular NPM package .. cron
This won't be suitable for everyone, but if your application is already setup to take commands via a socket, you can use netcat to issue a commands via cron proper.
echo 'mycommand' | nc -U /tmp/myapp.sock
node-crontab allows you to edit system cron jobs from node.js. Using this library will allow you to run programs even after your main process termintates. Disclaimer: I'm the developer.
node-schedule A cron-like and not-cron-like job scheduler for Node.
I am the auhor of node-runnr . It have a very simple approach to create job. Also its very easy and clear to declare time and interval. For example, to execute a job at every 10min 20sec,
Runnr.addIntervalJob('10:20', function(){...}, 'myjob')
To do a job at 10am and 3pm daily,
Runnr.addDailyJob(['10:0:0', '15:0:0'], function(){...}, 'myjob')
Its that simple. For further detail: https://github.com/Saquib764/node-runnr
Source: Stackoverflow.com