Wouldn’t it be nice to get a text message if one of your websites is down? In this tutorial, I’ll show you how to build a minimum viable uptime monitoring service.

Edit .env:

## Uptime Monitoring Tutorial

We’ll use Node. I’ll assume that node and npm are installed on your system.

Let’s start from scratch.

First, let’s install isomorphic-fetch, twilio, and node-schedule:

Why these modules?

We’ll use:

• twilio to send an SMS alert when a site is down
• isomorphic-fetch to make a simple get request to some websites
• node-schedule to run our uptime-monitoring microservice at regular intervals

The above snippet makes a fetch request to the URIs in sites.

We’ll use async/await syntax, but you could just as well use then.

If you don’t want to usea for() loop, you could use this syntax:

## Sending An SMS With Twilio

First, we need to require the twilio node module. Sending an SMS is easy.

## If You Don’t Have Twilio Account

Create an account at twilio.com. Once you register, you’ll see your ACCOUNT SID and AUTH TOKEN in your dashboard. Lastly, you’ll need to buy a phone number (the first one is free) to dispatch the text messages.

What we have so far:

• given a list of sites, make a GET request to each site.
• If the site is down (e.g., resp.status === 404), then send a text message via twilio.

## Using Node-Schedule

We can use node-schedule to execute our function at regular intervals. Node schedule accepts a crontab and a callback as follows:

Putting everything together, we have:

Testing things out:

Here’s a link to the github repo.