{"_id":"@airlookjs/node-healthcheck","_rev":"3-8a657d4c6e204d412ef1f74ebaad2121","name":"@airlookjs/node-healthcheck","dist-tags":{"latest":"1.4.3"},"versions":{"1.4.2":{"name":"@airlookjs/node-healthcheck","version":"1.4.2","license":"MIT","_id":"@airlookjs/node-healthcheck@1.4.2","maintainers":[{"name":"smukkejohan","email":"public@johan.cc"}],"homepage":"https://github.com/airlookjs/node-healthcheck#readme","bugs":{"url":"https://github.com/airlookjs/node-healthcheck/issues"},"dist":{"shasum":"11130fa41e7206c496f88dbf54fd94239b7f9f62","tarball":"https://registry.npmjs.org/@airlookjs/node-healthcheck/-/node-healthcheck-1.4.2.tgz","fileCount":3,"integrity":"sha512-U6/fMy+4m/wJyqzG313ilmCv2usrQA05FbJgeloewr4l8pkkclSQCf1VXJLXtlJcRKbwhZ4gCe0jXPHBjDreFg==","signatures":[{"sig":"MEYCIQDyhsl9Iiz8aXZSJ+BNYIbBF+mycaKyDphBsB4wR341bAIhAMruAE/PcLyGYA1JhZUoh10Pwm9SIpHxdkPXGj2LjDnN","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10258},"main":"dist/healthcheck.routes.js","gitHead":"32a6b5805f0da237b3a2c0bf744ca5b3155c1858","scripts":{"test":"mocha --require @babel/register 'src/*.spec.js'","build":"rm -rf ./dist && babel src --out-dir ./dist --ignore '**/*.spec.js'"},"_npmUser":{"name":"smukkejohan","email":"public@johan.cc"},"repository":{"url":"git+https://github.com/airlookjs/node-healthcheck.git","type":"git"},"_npmVersion":"10.2.4","description":"Utility libraryto quickly set up health and status endpoints for node applications with xml and json responses. Routers for express and fastify are included.","directories":{},"_nodeVersion":"20.11.1","dependencies":{"lodash":"4.17.21","express":"4.18.2","xmlbuilder2":"3.1.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@8.10.2","devDependencies":{"mocha":"10.3.0","sinon":"17.0.1","should":"13.2.3","supertest":"6.3.4","@babel/cli":"7.23.9","@babel/core":"7.23.9","@babel/node":"7.23.9","@babel/register":"7.23.7","semantic-release":"23.0.2","@babel/preset-env":"7.23.9","@semantic-release/git":"10.0.1","@semantic-release/npm":"11.0.2","@semantic-release/github":"9.2.6","@semantic-release/changelog":"^6.0.3"},"_npmOperationalInternal":{"tmp":"tmp/node-healthcheck_1.4.2_1708596168263_0.2646916952477052","host":"s3://npm-registry-packages"}},"1.4.3":{"name":"@airlookjs/node-healthcheck","version":"1.4.3","main":"dist/healthcheck.routes.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/airlookjs/node-healthcheck.git"},"scripts":{"build":"rm -rf ./dist && babel src --out-dir ./dist --ignore '**/*.spec.js'","test":"mocha --require @babel/register 'src/*.spec.js'"},"engine":"node >= 22.18.0","publishConfig":{"access":"public"},"dependencies":{"express":"^4.21.2","lodash":"^4.17.21","xmlbuilder2":"^3.1.1"},"devDependencies":{"@babel/cli":"7.23.9","@babel/core":"7.23.9","@babel/node":"7.23.9","@babel/preset-env":"7.23.9","@babel/register":"7.23.7","@semantic-release/changelog":"^6.0.3","@semantic-release/git":"10.0.1","@semantic-release/github":"9.2.6","@semantic-release/npm":"11.0.2","mocha":"^10.8.2","semantic-release":"23.0.2","should":"13.2.3","sinon":"17.0.1","supertest":"^7.1.4"},"packageManager":"pnpm@10.16.1","_id":"@airlookjs/node-healthcheck@1.4.3","gitHead":"108a10f64a94024502c3747d4c495adcff305545","description":"Utility libraryto quickly set up health and status endpoints for node applications with xml and json responses. Routers for express and fastify are included.","bugs":{"url":"https://github.com/airlookjs/node-healthcheck/issues"},"homepage":"https://github.com/airlookjs/node-healthcheck#readme","_nodeVersion":"20.19.5","_npmVersion":"10.8.2","dist":{"integrity":"sha512-U70zVYPmnSMMEhmlSe55q928dTvQgM2Af1TV/Lv43N8Lx4OxGg0qCCnSMw3VUrZZHpbfGtfPxUz5TcWGu1OMNg==","shasum":"f76ccb9f1d372607f9ec6b8b4124877e805e4303","tarball":"https://registry.npmjs.org/@airlookjs/node-healthcheck/-/node-healthcheck-1.4.3.tgz","fileCount":3,"unpackedSize":10627,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDwn2us3pVsGEy4bpRUiddIGToZjzLcziQZ7FGoxyjoQwIgDOQkDqIXrf1AVqjCAtkSC9t6OVkSctXr5zVazxRaA5k="}]},"_npmUser":{"name":"smukkejohan","email":"public@johan.cc"},"directories":{},"maintainers":[{"name":"smukkejohan","email":"public@johan.cc"},{"name":"olekristensen","email":"ole@kristensen.name"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/node-healthcheck_1.4.3_1758099658409_0.7155707531137296"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-22T10:02:48.189Z","modified":"2025-09-17T09:00:58.836Z","1.4.2":"2024-02-22T10:02:48.463Z","1.4.3":"2025-09-17T09:00:58.627Z"},"bugs":{"url":"https://github.com/airlookjs/node-healthcheck/issues"},"license":"MIT","homepage":"https://github.com/airlookjs/node-healthcheck#readme","repository":{"type":"git","url":"git+https://github.com/airlookjs/node-healthcheck.git"},"description":"Utility libraryto quickly set up health and status endpoints for node applications with xml and json responses. Routers for express and fastify are included.","maintainers":[{"name":"smukkejohan","email":"public@johan.cc"},{"name":"olekristensen","email":"ole@kristensen.name"}],"readme":"Utility libraryto quickly set up health and status endpoints for node applications with xml and json responses. Routers for express and fastify are included. \n\n[![NPM Version](https://img.shields.io/npm/v/@airlookjs/node-healthcheck.svg?style=flat-square&colorB=51C838)](https://www.npmjs.com/package/@airlookjs/node-healthcheck)\n\n[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)\n\n## Installation:\n    $ npm install '@airlookjs/node-healthcheck'\n\n## Usage\n\n### Simple check\nThe simplest check has just a name and a check function.\n```javascript\nconst check = {\n    name: `Check directory exists`,\n    checkFn: function() {\n            if (!fs.existsSync(\"/tmp/dir\")) {\n                throw new Error(`/tmp/dir does not exist`)\n            }\n        }\n}\n```\nOptionally the check may have a description that is prepended to the output status message. \n\n\n### timeouts\nA specific timeout that the function should execute within to not return a timeout error can be set. The library sets a default timeout of 5000 ms. \n\n```javascript\nconst check = {\n    name: `Check should complete very quickly`,\n    timeout: 200,\n    checkFn: function() {\n            await fastFunction()\n        }\n}\n```\n\n\n### returning status\nBy default a succesfull check return the message 'OK', return a string to set a custom message. The output message is concatenated from the description and the message.  \n\n```javascript\nconst check = {\n    name: `API connectivity check `,\n    description: `Check that localhost can reach API`\n    checkFn: function() {\n            const resp = await api.get('/')\n            return 'test succesfull'\n        }\n}\n```\n\nReturns message on succesfull check: \"Check that localhost can reach API: test succesfull\"\n\nThe message can also be overwritten completely\n\n```javascript\nconst check = {\n    name: `API connectivity check `,\n    description: `Check that localhost can reach API`\n    checkFn: function(check) {\n            const resp = await api.get('/')\n            check.message = \"we ain't got no problem\"\n        }\n}\n```\n\n### Status levels\nThe library supports an OK, ERROR and WARNING state. \nOK is produced from a check running with no undcaught errors and no timeout. \nERROR is produced when the check function throws or times out. \n\nWarning is produced by setting the flag warnOnError and then throwing. \n\n```javascript\nconst check = {\n    name: `storage check`,\n    checkFn: function(check) {\n            const availableBytes = getFreeStorage()\n            \n            if (availableBytes < config.criticalStorageLimit) {\n                throw new Error(\"Storage is critically low, application will malfunction\")\n            }\n            if (availableBytes < config.warningStorageLimit) {\n                check.warnOnError = true\n                throw new Error(\"Storage is low, clean up soon\")\n            }\n            \n        }\n}\n```\n\nAll status outputs may also be set manually without throwing. \n\n```javascript\nconst check = {\n    name: `storage check`,\n    checkFn: function(check) {\n            const availableBytes = getFreeStorage()\n            \n            if (availableBytes < config.criticalStorageLimit) {\n                check.status = \"ERROR\"\n                return \"storage is critical\"\n            }\n            if (availableBytes < config.warningStorageLimit) {\n                check.status = \"WARNING\"\n                return \"storage is low\"\n            }\n            check.status = \"OK\"\n            return \"storage is sufficient\"\n            \n        }\n}\n```\n\nA custom status may also be set but at the moment the applicationstatus only works for the following states \"OK\", \"ERROR\", \"WARNING\". Most severe state is always reported as applicationstatus   \n\n### Using express router and multiple application tests:\n\n```javascript\nimport express from 'express'\nimport cors from 'cors'\nimport { getExpressHealthRoute } from '@airlookjs/node-healthcheck'\n\nconst app = express()\napp.use(cors())\n\nconst checks = [{\n    name: `Connection to folder`,\n    description: `Is directory readable at ${config.paths.renderTemp}`,\n    checkFn: function() {\n            if (!fs.existsSync(config.paths.renderTemp)) {\n                throw new Error(`RenderTemp folder could not be accessed.`)\n            }\n        }\n},\n{\n    name: `Connection to PixelPower playout server 1`,\n    description: `Is directory readable at ${config.paths.pixelpower.media.server1}`,\n    checkFn: function() {\n        if (!fs.existsSync(config.paths.pixelpower.media.server1)) {\n            throw new Error(`Connection not established`)\n        }        \n    }\n},\n{\n    name: `Connection to airlook API`, \n    description: `Can fetch data from endpoint at ${config.AIRlOOK_API_ENDPOINT}outputs`,\n    checkFn: async function() { \n        await api.get('outputs')\n        return \"Data fetched\"\n    }\n},\n]\n\napp.use('/status', getExpressHealthRoute(checks));\n\n```\n\nThe status endpoint will return either xml or json depneding on the Accept header in the request. An ERROR state is returned with code 503 Service unavailable. ","readmeFilename":"README.md"}