I have this code snippet that needs to execute on 31 Dec 11:59:59 every year. I working in Mean.Js framework so it would be great to have a solution specific to Node.js.
But, even plain Javascript or generic algorithms are also welcome.
I have this code snippet that needs to execute on 31 Dec 11:59:59 every year. I working in Mean.Js framework so it would be great to have a solution specific to Node.js.
But, even plain Javascript or generic algorithms are also welcome.
If you want to use node.js anyway, you can use cron: simply create a cron job with the desired time, date and your script.
Otherwise, the strategy for doing it would be this:
Date
Date
(31st Dec of the current year (which you need to determine) at 23:59)Note for future questions: read the SO help docs. Include what you tried so far and add code if you expect code in the answers.
You basically trying to schedule something and for this you don't need any kind of algorithm. Only thing that you need to know is crontab
Note: I am assuming you are working on either Mac or Linux. There must be something like crontab in windows too, do some research.
A crontab is a simple text file with a list of commands meant to be run at specified times. These commands (and their run times) are then controlled by the cron daemon, which executes them in the system background.
The steps you need to follow are as follows:
How to write Cronjob?
<minute> <hour> <month day> <month> <week day> <command to execute>
* * * * * specifies "every minute, every hour, every day, every month, every week"
5 18 2 2 3 specifies the 5th minute or the hour, the 18th hour of the day, the second of the moth , second month (february) or the third week day. So this schedule will run when all this conditions are true i.e.; 6:05 PM on February 2nd
Similarly,
30 2 * * 6 specifies scripts to run every saturday at 2:30 pm
.
So that was about cronjob. Let me give you an example.
Let's say you got: cronjob.txt:
* * * * * ~/pathtofile/call_node_program.sh
call_node_program.sh:
node myfile.js
So your call_node_program.sh would do the job for you.
I am leaving on you to do the research and write the pattern for 31 Dec 11:59:59 every year. Cheers.