npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

health-check-plus

v1.0.1

Published

Heath checks on steroids!

Downloads

7

Readme

Health Check Plus for Express.js

This npm package provides a supercharged out-of-the-box health check middleware for Express.js applications. It simplifies the process of adding a health check endpoint to your backend Node.js projects, especially when deploying on AWS or other platforms.

Table of Contents

Installation

To install the package, use npm:

npm install --save health-check-plus

Usage

Simply import the healthCheckPlus into your Express.js application and use it as a middleware. This middleware provides a comprehensive health check endpoint with version information and the latest commit hash.

Examples

ES Module Usage

import express from 'express';
import { healthCheckPlus } from 'health-check-plus';

const app = express();

/** 
 * Add health check middleware
  Remember, you don't need to give path or route here we support these routes out of the box, just hit any one of these:
  '/HealthCheck'
  '/HealthCheck/'
  '/Health-Check'
  '/Health-Check/'
  '/health-check'
  '/health-check/'
  '/healthCheck'
  '/healthCheck/'
  '/health-check-plus'
  '/health-check-plus/'
**/
app.use(healthCheckPlus);

// Other routes and middleware can be defined here

// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

CommonJS Usage

const express = require('express');
const { healthCheckPlus } = require('health-check-plus');

const app = express();

/** 
 * Add health check middleware
  Remember, you don't need to give path or route here we support these routes out of the box, just hit any one of these:
  '/HealthCheck'
  '/HealthCheck/'
  '/Health-Check'
  '/Health-Check/'
  '/health-check'
  '/health-check/'
  '/healthCheck'
  '/healthCheck/'
  '/health-check-plus'
  '/health-check-plus/'
**/
app.use(healthCheckPlus);    

// Other routes and middleware can be defined here

// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

Response in Browser

API

healthCheckPlus Middleware Function

Middleware function for performing a supercharged health check operation. It retrieves version information and the latest commit hash and sends it as a JSON response.

  • healthCheckPlus(req: Request, res: Response, next: NextFunction): Middleware function for performing a supercharged health check operation.

    • req: Express Request object.
    • res: Express Response object.
    • next: Express NextFunction object.

Health Checks

To facilitate health checks, this utility automatically updates the package.json file with the latest commit hash. This allows health checks to read the latest commit hash from the package.json file.

Code Explanation

  • The GetVersionInfo function retrieves version information from the package.json file and the latest commit hash from the associated Git repository.
  • It accepts two optional parameters: packageJsonPath (path to the package.json file) and versionInfo (existing version information).
  • The AppVersionInfo class represents version information with properties for version and commit hash.
  • The utility exports the AppVersionInfo class and the GetVersionInfo function for external use.

Why Was This Package Created?

This npm package was created to address the repetitive task of adding a health check endpoint to backend Node.js projects, especially when deploying on AWS or other platforms. The author of this package found it cumbersome to manually create health checks for each project and decided to create a supercharged solution that can be easily integrated into any Express.js application.

License

This project is licensed under the MIT License.