{"id":15285683,"url":"https://github.com/gkampitakis/fastify-custom-healthcheck","last_synced_at":"2025-07-06T17:38:32.951Z","repository":{"id":38211987,"uuid":"283414713","full_name":"gkampitakis/fastify-custom-healthcheck","owner":"gkampitakis","description":"Fastify plugin to add health route in your server that asserts custom functions","archived":false,"fork":false,"pushed_at":"2025-06-23T11:37:46.000Z","size":62,"stargazers_count":16,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T14:06:09.136Z","etag":null,"topics":["fastify","fastify-plugin","healthcheck","npm-package"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fastify-custom-healthcheck","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkampitakis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-29T06:12:22.000Z","updated_at":"2024-12-19T17:30:44.000Z","dependencies_parsed_at":"2024-06-21T14:18:15.329Z","dependency_job_id":"8adb71ba-4de0-4707-bbce-3caf1c8a1f08","html_url":"https://github.com/gkampitakis/fastify-custom-healthcheck","commit_stats":{"total_commits":59,"total_committers":6,"mean_commits":9.833333333333334,"dds":0.3389830508474576,"last_synced_commit":"00aa8c06166ddabbdb3f05cb05913dd500d0f12e"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/gkampitakis/fastify-custom-healthcheck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-custom-healthcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-custom-healthcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-custom-healthcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-custom-healthcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkampitakis","download_url":"https://codeload.github.com/gkampitakis/fastify-custom-healthcheck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-custom-healthcheck/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263943793,"owners_count":23533643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","healthcheck","npm-package"],"created_at":"2024-09-30T15:07:08.727Z","updated_at":"2025-07-06T17:38:32.929Z","avatar_url":"https://github.com/gkampitakis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify Custom Healthcheck\n\n[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/standard/semistandard)\n[![Build Status](https://travis-ci.com/gkampitakis/fastify-custom-healthcheck.svg?branch=master)](https://travis-ci.com/gkampitakis/fastify-custom-healthcheck)\n\n`fastify-custom-healthcheck` is a plugin for creating a health route with custom evaluations.\n\n\n## Install\n\n```bash\nnpm i fastify-custom-healthcheck\n```\n\n## Usage\n\nRequire the module and just register it as any other fastify plugin. From `fastify-custom-healthcheck` on decorator is going to be added to your server for adding custom health checks.\n\n```javascript\nconst fastify = require('fastify')();\nconst customHealthCheck = require('fastify-custom-healthCheck');\n\nfastify.register(customHealthCheck, options).then(() =\u003e {\n    fastify.addHealthCheck('metric', () =\u003e {\n        return new Promise((resolve) =\u003e setTimeout(resolve, 5000));\n    });\n});\n\nfastify.listen(3000);\n```\n\n## API\n\n### register plugin\n\n```javascript\nfastify.register(customHealthCheck, {\n    path: '/health/check', // default health\n    info: {}, // custom information object\n});\n```\n\n### register options\n\n-   `path`: path where you can reach health check route.\n    -   default value: `'/health'`.\n-   `info`: object where you can define custom information you would like to include in healthcheck response object.\n-   exposeFailure: Flag that enables additional information to be presented in health check object when a check fails.\n    -   default value: `false`\n-   schema: If set to true, default schema is used for the route definition, if to false - no schema. If object is passed, it will be used as a schema. This can be used to enable support for custom type providers, e. g. zod or typebox. \n    -   default value: `true`\n\n### Decorator\n\nAfter registering plugin you can use the decorator for adding custom health checks.\n\n```javascript\nfastify.addHealthCheck(label, () =\u003e {}, { value: true });\n```\n\n### decorator options\n\n-   value: If you add on `addHealthCheck` a value, when computing health check an equality check happens between evaluation and the value returned by the health check function. If the values are different health check fails.\n\n## Example response \n\n```json\n{\n  \"healthChecks\": {\n    \"mongo\": {\n      \"status\": \"FAIL\",\n      \"reason\": \"MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017\\n    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {\\n  name: 'MongoNetworkError'\\n}]\"\n    },\n    \"kafka\": \"HEALTHY\",\n    \"redis\": \"HEALTHY\" \n  },\n  \"stats\": {\n    \"creationTime\": \"2020-08-04T19:16:29.766Z\",\n    \"uptime\": 0.303361107,\n    \"memory\": {\n      \"rss\": 50102272,\n      \"heapTotal\": 29270016,\n      \"heapUsed\": 16499104,\n      \"external\": 20754444,\n      \"arrayBuffers\": 19273278\n    }\n  },\n  \"info\": {\n    \"example\": \"Response\",\n  }\n}\n```\n\n## Acknowledgements\n\nThis module is inspired by [server-health](https://www.npmjs.com/package/server-health) and the need of having this functionality in fastify.\n\n### Example\n\nYou can also check an [example](./example) usage.\n\n### Issues\n\nFor any [issues](https://github.com/gkampitakis/fastify-custom-healthcheck/issues).\n\n## License \n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkampitakis%2Ffastify-custom-healthcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkampitakis%2Ffastify-custom-healthcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkampitakis%2Ffastify-custom-healthcheck/lists"}