Skip to content

Instantly share code, notes, and snippets.



Last active May 1, 2018
What would you like to do?
How to get a Node.js function to run once on the last day of each month
const moment = require('moment');
const someAction = () => console.log('Actioning...');
const wait = ms => new Promise((resolve, reject) => setTimeout(resolve, ms));
const startCron = async () => {
while (true) {
if (
moment().date() ===
) {
await wait(moment.duration(1, 'day').asMilliseconds());
console.log('Starting cron service...');

This comment has been minimized.

Copy link
Owner Author

@magician11 magician11 commented May 1, 2018

For more information on the the moment library, have a look at

A walkthrough of this gist is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.