Why you should add a healthcheck endpoint
If you’ve ever deployed an app and crossed your fingers hoping it “just works”… this one’s for you.
Let me introduce you to the humble but mighty: healthcheck endpoint.
🧠 What’s a healthcheck?
A healthcheck is a simple endpoint (like /health
or /status
) that lets you – or your hosting provider – verify if your app is alive and kicking.
It’s usually a super lightweight GET route that returns something like:
{
"status": "ok"
}
But it can go deeper if you want – checking your database, cache, third-party APIs, etc.
Why you need one
First of all, how do you currently make sure that your backend is deployed ? Do you open the frontend and test a happy path to see if it works? Do you call a random endpoint to see if it sends a response ? If you're doing the first, you're wasting time. If you're doing the latter, you are using your endpoint as a healthcheck. 😅
Moreover, modern infra tools (like Docker, Kubernetes, Vercel, AWS, or your VPS watchdog) often rely on healthchecks to know when to restart your app or mark it as healthy.
Without a healthcheck, you’re flying blind. Your app could be in a half-dead zombie state – not crashed, but not responding either.
Also, if you’re working with uptime monitoring tools (like UptimeRobot, Better Uptime, or even your own script), a healthcheck is the go-to endpoint to ping regularly.
How to add one
Here’s a simple example in Node.js with Express:
// server.js
import express from 'express';
const app = express();
app.get('/health', (req, res) => {
res.status(200).json({ status: 'ok' });
});
app.listen(3000, () => console.log('Server is running on port 3000'));
This is the bare minimum: if your server is running and responding, the endpoint will return 200.
Now let’s make it slightly smarter by checking the DB connection:
app.get('/health', async (req, res) => {
try {
await db.ping(); // or db.authenticate() depending on your lib
res.status(200).json({ status: 'OK', dbStatus: 'OK' });
} catch (e) {
res.status(500).json({ status: 'OK', dbStatus: 'KO' });
}
});
You can get as fancy as you like – just keep it fast.
What not to do
- ❌ Don’t require authentication for your healthcheck route. Keep it public (but don’t expose sensitive data).
- ❌ Don’t make it heavy. No full page renders, no slow database joins.
- ❌ Don’t forget to actually use it in your infra or monitoring tools.
💡 TL;DR
- Healthcheck endpoints help you detect when your app is down or misbehaving.
- Just create a simple GET
/health
route that returns a 200 status. - Your devops future self will thank you.
Want me to show how to do it in Next.js API routes or with serverless functions? Ping me. Or just check my blog for more dev goodness. 😉