{"_id":"@coates/express-healthcheck-middleware","_rev":"3-d057334eb33e868349ca3cb7ca067611","name":"@coates/express-healthcheck-middleware","description":"An express middleware that can be used for healthchecks","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@coates/express-healthcheck-middleware","version":"1.0.0","description":"An express middleware that can be used for healthchecks","main":"index.js","scripts":{"test":"npm install && node_modules/.bin/jasmine test/test.js","example":"npm install && node ./examples/server.js"},"repository":{"type":"git","url":"git+https://gitlab.com/coates/express-healthcheck-middleware.git"},"author":{"name":"Nathan Hyman"},"license":"MIT","bugs":{"url":"https://gitlab.com/coates/express-healthcheck-middleware/issues"},"homepage":"https://gitlab.com/coates/express-healthcheck-middleware#README","dependencies":{"lodash":"^4.17.4"},"devDependencies":{"express":"^4.15.3","jasmine":"^2.6.0","jasmine-spec-reporter":"^4.1.1"},"gitHead":"28cb565448176babc4c458206ad50c9cb44eedab","_id":"@coates/express-healthcheck-middleware@1.0.0","_shasum":"f4cdc0a10ea48fc0f75d79a265f62c9d1ace8ce0","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"nathanhyman","email":"nathan.hyman@coatesgroup.com"},"dist":{"shasum":"f4cdc0a10ea48fc0f75d79a265f62c9d1ace8ce0","tarball":"https://registry.npmjs.org/@coates/express-healthcheck-middleware/-/express-healthcheck-middleware-1.0.0.tgz","integrity":"sha512-fpqwj8uVpVbZF5UQxjtoCZDU3fC8fOdgi6oxKNVr4fmw97MLzrEIlsx5pHFhBezCqGD47x0UclWuoV5V+Z7Fiw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGXpYmJUWtErScycfhz6TGo7jBXb0Eb4tAFzXqLQo5nyAiBlhOJlX+EEoaPI4H/2FNo2rGucQrneYg68bK0H4XwCJw=="}]},"maintainers":[{"name":"nathanhyman","email":"nathan.hyman@coatesgroup.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-healthcheck-middleware-1.0.0.tgz_1499927539878_0.8636354422196746"}}},"readme":"# Express Healthcheck Middleware\n\n## What it is\n\nThis module can be plugged into express applications to expose a health check endpoint for external services.\n\n## How to use it\n\nThis module will export a middleware generator. The generator can be used by itself or by passing in an optional argument.\nThe generator returns an express Middleware function with parameters `req` and `res`\n\nBy default the generator will export a middleware that returns the following json object when triggered\n\n|  Paramter  |              Description               |                    Default values                    |\n|------------|----------------------------------------|------------------------------------------------------|\n| version    | The current version of the application | `process.env.VERSION` or `null` if that is undefined |\n| status     | The text health status                 | 'ok' or 'error'                                      |\n| statusCode | The HTTP status code                   | `200` or `500`                                       |\n| uptime     | The uptime of the node application     | float eg `50.301`                                      |\n\nExtra Optional Arguments\n\n| Paramter |          Description          |     Example values    |\n|----------|-------------------------------|-----------------------|\n| data     | Only checked on Error objects | { connection: false } |\n\n\nThe `status`, `statusCode` can be overriden if a test function returns the values.\n\n### Arguments\n\nThe options argument contains the following parameters\n\n`testFunction`\n\n- A function returning a promise (or just a regular synchronous function) that can run any extra tests.\n- This should resolve or reject with a Object containing any extra information to display.\n- `status`, `statusCode` attributes can be returned to override the defaults noted above\n- If an error is thrown it will be caught and return the `Error.message` + a `500` `statusCode` obj along with anything put into `Error.data`\n\nIf a non object is returned from this function then the middleware will wrap it in the in a `data` object with the key `info`\n\nEG `return 'this is a message'` becomes\n\n```\n{\n  data: {\n    info: 'this is a message'\n  }\n}\n```\n\n## Examples\n\nBasic use\n\n```javascript \nconst healthCheckMiddlewareGenerator = require('express-healthcheck-middleware');\nconst healthCheckMiddleware = healthCheckMiddlewareGenerator();\n\napp.use('/health', healthCheckMiddleware);\n```\n\nThis example will also run an extra test case of checking if the Database connection is alive.\n(Assume the function `checkDB` resolves to a object with `connection` of `true` or `false`)\n\n```javascript\nconst healthCheckMiddlewareGenerator = require('express-healthcheck-middleware');\nconst extraTestFunction = function() {\n  return new Promise((resolve, reject) => {\n    checkDB()\n      .then(data => {\n        if (data.connection === true) {\n          resolve({ databaseConnection: true })\n        } else {\n          let error = new Error(\"Database is not connected\")\n          error.data = { databaseConnection: data.connection }\n          error.statusCode = 501;\n          error.status = 'warning';\n          reject(error);\n        }\n      })\n  })\n}\n\nconst healthCheckMiddleware = healthCheckMiddlewareGenerator({ testFunction: extraTestFunction });\n\napp.use('/health', healthCheckMiddleware);\n```\n\n\n## Developing\n\nRunning this command will startup a docker container mounting your source into `/home/`\nYou can then `cd` into `/home` and dev as normal. Care should be taken for root files when creating them within the container.\n\n`docker run -it -v $PWD/:/home/ --rm node bash`\n\n### NPM commands\n\n- `npm install` to install the application for development\n- `npm test` to run all tests\n- `npm run example` to load up a server with an example use (see `examples/server.js`)\n\n# TODO\n\n- Add function to manipulate/format final json data.\n- Add more error handling","maintainers":[{"email":"jon.calderingoni@coatesgroup.com","name":"cholas"},{"email":"deanrather+npm@gmail.com","name":"deanrather"},{"email":"nathan.hyman@coatesgroup.com","name":"nathanhyman"}],"time":{"modified":"2022-06-12T16:19:09.497Z","created":"2017-07-13T06:32:19.985Z","1.0.0":"2017-07-13T06:32:19.985Z"},"homepage":"https://gitlab.com/coates/express-healthcheck-middleware#README","repository":{"type":"git","url":"git+https://gitlab.com/coates/express-healthcheck-middleware.git"},"author":{"name":"Nathan Hyman"},"bugs":{"url":"https://gitlab.com/coates/express-healthcheck-middleware/issues"},"license":"MIT","readmeFilename":"README.md"}