Check your app is Allgood with a beautiful /healthcheck page and API.
Compatible with Express, Fastify, Hono, Next.js (App Router) and anything else built on the Fetch API's Request/Response β Bun, Deno, Remix and SvelteKit included.
Use it for smoke tests, monitoring, debugging and alerting. It can be used as a healthcheck page for UptimeRobot or similar monitoring services.
Inspired by the RubyGem of the same name.
npm i -s @joshghent/allgood
yarn add @joshghent/allgood
pnpm add @joshghent/allgood
Next, add a healthcheck route to your app. We have examples below for popular frameworks.
Point your agent at llms.txt β it is written for them: the install command, a snippet per framework, every config option and the mistakes to avoid. Something like:
Add a health check to this app using @joshghent/allgood. Follow https://raw.githubusercontent.com/joshghent/allgood/main/llms.txt
// app/api/healthcheck/route.ts
import { createHealthCheck } from '@joshghent/allgood';
export const runtime = 'nodejs'; // not 'edge' β the checks need Node APIs
export const dynamic = 'force-dynamic'; // never serve a cached result
export const GET = createHealthCheck({
db_connection: process.env.DATABASE_URL,
cache_connection: process.env.REDIS_URL,
checks: {
db_connection: true,
cache_connection: true,
},
});The same createHealthCheck(...) works as a handler anywhere that passes a standard Request and expects a Response back (Bun, Deno, Remix, SvelteKit).
import express from "express";
import { createHealthCheck } from '@joshghent/allgood';
const app = express();
const healthCheck = createHealthCheck({
db_connection: process.env.DATABASE_URL,
cache_connection: process.env.REDIS_URL,
checks: { // default checks
db_connection: false,
db_migrations: false,
cache_connection: false,
disk_space: true,
memory_usage: true,
outbound_internet: true,
cpu_usage: true,
dynamodb: false
},
});
app.get("/healthcheck", healthCheck);
app.listen(3000, () => {
console.log("Express server running on http://localhost:3000");
});import fastify from 'fastify'
import { createHealthCheck } from '@joshghent/allgood';
const app = fastify()
const healthCheck = createHealthCheck({
db_connection: process.env.DATABASE_URL,
cache_connection: process.env.REDIS_URL,
checks: {
db_connection: true,
cache_connection: true,
},
})
// Health check route
app.get('/healthcheck', healthCheck)
// Run the server!
const start = async () => {
try {
await app.listen({ port: 3000 })
} catch (err) {
app.log.error(err)
process.exit(1)
}
}
start()import { Hono } from 'hono'
import { serve } from '@hono/node-server'
import { createHealthCheck } from '@joshghent/allgood';
const app = new Hono()
const healthCheck = createHealthCheck({
db_connection: process.env.DATABASE_URL,
cache_connection: process.env.REDIS_URL,
checks: {
db_connection: true,
cache_connection: true,
},
})
app.get('/healthcheck', healthCheck)
const PORT = 3000
console.log(`Server is running on port ${PORT}`)
serve({
fetch: app.fetch,
port: PORT
})pnpm add @aws-sdk/client-dynamodbconst healthCheck = createHealthCheck({
dynamodb_table: process.env.DYNAMODB_TABLE,
checks: { dynamodb: true },
});The check runs DescribeTable. Region, credentials and endpoint come from the AWS SDK default chain (AWS_REGION, AWS_ENDPOINT_URL_DYNAMODB, profiles, IAM roles).
Allgood will also return a JSON object with healthcheck information for programmatic usage. Here is an example of what it will return:
curl --request GET --url http://api.example.com/healthcheck
{
"status": "pass",
"description": "Health check response, generated by allgood.",
"results": {
"memory_usage": {
"status": "pass",
"value": "54.09%",
"componentName": "memory",
"message": "Memory usage is below 80%",
"time": 0
},
"disk_space": {
"status": "pass",
"value": "288.37 GB",
"componentName": "disk",
"message": "Disk space is greater than 1GB",
"time": 34
},
"cache_connection": {
"componentName": "cache_connection",
"status": "pass",
"message": "Cache connection successful",
"value": "true",
"time": 50
},
"db_connection": {
"componentName": "db_connection",
"status": "pass",
"message": "Database connection successful",
"value": "true",
"time": 155
},
"outbound_internet": {
"status": "pass",
"value": "true",
"componentName": "egress",
"message": "Outbound internet is working",
"time": 434
},
"cpu_usage": {
"status": "pass",
"value": "32.09%",
"componentName": "cpu",
"message": "CPU usage is below 80%",
"time": 1002
}
}
}200 when every check passes or only warns, 503 when any check fails β so a monitor can alert on the status code without parsing the body.
The database check keeps one single-connection pool per connection string for the life of the process, rather than opening a new one per request. The Redis check opens a connection per check and always closes it. To close the database pools on shutdown:
import { closeDbClients } from '@joshghent/allgood';
process.on('SIGTERM', async () => {
await closeDbClients();
process.exit(0);
});Good point! Allgood will only work whilst your app does. But, if your monitoring service is calling /healthcheck, it will simply timeout.
Nope, add it anywhere you want.
pnpm test # unit tests, no services needed
podman compose up -d --wait # Postgres, MySQL, Redis, Memcached and DynamoDB Local
pnpm test:integration # real services and real Express, Fastify and Hono serversTL;DR: Use it however you want, just don't blame me if it blows up or distribute a closed source version. GNU General Public License v3.0

