The usual answer is to sign up for an uptime monitoring service. On Val Town it's one cron-triggered val: fetch your URL on a schedule, remember the last known status in blob storage, and send yourself an email with std/email only when the status changes — one email when the site goes down, one when it recovers.
The monitor
Section titled “The monitor”View and run this example on Val Town
import { blob } from "https://esm.town/v/std/blob/main.ts";import { email } from "https://esm.town/v/std/email";
// The URL to monitor. Change this to your website.const URL_TO_MONITOR = "https://example.com";
export default async function () { let up = false; let detail = ""; try { const res = await fetch(URL_TO_MONITOR); up = res.ok; detail = `HTTP ${res.status}`; } catch (e) { detail = String(e); }
const last = await blob.getJSON("last-status") as { up: boolean } | undefined; if (last?.up === up) return; // no change, stay quiet
await blob.setJSON("last-status", { up }); if (last === undefined) return; // first run: just record the baseline
await email({ subject: up ? `Recovered: ${URL_TO_MONITOR} is back up (${detail})` : `Down: ${URL_TO_MONITOR} (${detail})`, text: `${URL_TO_MONITOR} is ${up ? "back up" : "down"}. ${detail}`, });}Because the last status is stored in blob storage, you never get repeat alerts while the site stays down. The first run only records a baseline, so remixing it never sends a surprise email.
Set it up
Section titled “Set it up”- Remix this template — click the Remix button in the top right corner.
- In
monitor.ts, changeURL_TO_MONITORto your website's URL.
That's it: no API keys, no environment variables, no signup for a monitoring
service. To test it, point URL_TO_MONITOR at a URL that 404s and click
Run on monitor.ts twice — the first run records the baseline, the
second one emails you.
- Alerts go to your Val Town account email — that's where std/email delivers by default.
- The template checks every five minutes (
*/5 * * * *). On the free plan crons run at most once every 15 minutes, so change the schedule to*/15 * * * *(or upgrade to Pro for up to once a minute). - A response is counted as up when
res.okis true (status 200–299), and as down on any other status or a network error.
Next steps
Section titled “Next steps”- Cron reference — schedule types and limits
- std/email reference — subject, attachments, and sending limits
- Website uptime tracker — community variations on the same idea