Express Production Setup - 1 | Express Health Checker
index.js
const express = require("express")
const quicker = require("./quicker")
const app = express()
app.get("/", (req, res) => {
res.send("hello")
})
app.get("/health", (req, res) => {
const HealthData = {
application: quicker.getApplicatonHealth(),
system: quicker.getSystemHealth(),
timestemp: Date.now(),
}
res.json(HealthData)
})
app.listen(3000, () => console.log("app runnning on port 3000"))
quicker.js
const os = require("os")
module.exports = {
getSystemHealth: () => {
return {
cpuUsge: os.loadavg(),
totalMemory: os.totalmem() / 1024 / 1024 + "MB",
freeMemory: os.freemem() / 1024 / 1024 + "MB",
}
},
getApplicatonHealth: () => {
return {
uptime: os.uptime() + "seconds",
memoryUsage: {
heapTotal: `${process.memoryUsage().heapTotal / 1024 / 1024} MB`,
heapUsed: `${process.memoryUsage().heapUsed / 1024 / 1024} MB`
}
}
}
}
Comments
Post a Comment