@visulima/health-check
Version:
A library built to provide support for defining service health for node services. It allows you to register async health checks for your dependencies and the service itself, provides a health endpoint that exposes their status, and health metrics.
35 lines (33 loc) • 1.21 kB
JavaScript
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const DISPLAY_NAME = "Node Environment Check";
const nodeEnvironmentCheck = /* @__PURE__ */ __name((expectedEnvironment) => async () => {
const environment = process.env.NODE_ENV;
let errorMessage;
if (environment !== void 0 && expectedEnvironment !== void 0 && environment !== expectedEnvironment) {
errorMessage = `NODE_ENV environment variable is set to "${environment}" instead of "${expectedEnvironment}".`;
} else if (!environment) {
errorMessage = ["Missing NODE_ENV environment variable.", "It can make some parts of the application misbehave"].join(" ");
}
if (errorMessage !== void 0) {
return {
displayName: DISPLAY_NAME,
health: {
healthy: false,
message: errorMessage,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
}
};
}
return {
displayName: DISPLAY_NAME,
health: {
healthy: true,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
},
meta: {
env: environment
}
};
}, "nodeEnvironmentCheck");
export { nodeEnvironmentCheck as default };