Skip to content

Instantly share code, notes, and snippets.

@adamhenson
Last active February 5, 2019 14:20
Show Gist options
  • Save adamhenson/1a65ec49cf043f3ba8005bc97719c8de to your computer and use it in GitHub Desktop.
Save adamhenson/1a65ec49cf043f3ba8005bc97719c8de to your computer and use it in GitHub Desktop.
A Node.js cron job to ping an endpoint and log the response status code.
import fetch from 'node-fetch';
import schedule from 'node-schedule';
const apiUrl = 'http://api:3000/healthcheck';
const ping = async () => {
try {
const response = await fetch(apiUrl);
console.log('status', response.status);
} catch (error) {
console.log('error', error);
}
};
// every day at 8:00am
schedule.scheduleJob('0 8 * * *', ping);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment