Skip to content

Instantly share code, notes, and snippets.

@kumarasinghe
Created April 13, 2023 17:54
Show Gist options
  • Save kumarasinghe/49fa5586a6c585592b9f9c1e916b3fbc to your computer and use it in GitHub Desktop.
Save kumarasinghe/49fa5586a6c585592b9f9c1e916b3fbc to your computer and use it in GitHub Desktop.
Node.js health check route
import os from "os";
import process from "process";
/* GET /api/health */
const stats = {
status: "OK",
system: {
hostname: os.hostname(),
free_memory_mb: Math.floor(os.freemem() / 1000000),
load_avg: os.loadavg(),
cpu_cores: os.cpus().length,
uptime_s: Math.round(os.uptime()),
},
process: {
memory_usage_mb: Math.floor(process.memoryUsage().rss / 1000000),
uptime_s: Math.round(process.uptime()),
},
};
res.json(stats);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment