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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nest-git-info

v0.0.10

Published

NestJS module for exposing Git build information via API endpoint

Downloads

24

Readme

nest-git-info

A NestJS module that exposes Git build information via an API endpoint. Automatically captures and exposes Git metadata during your build process which is useful for debugging which version of the code is running in live environments.

What does it do?

Once installed, this module:

  1. Automatically captures Git metadata during your build process including:

    • Git commit SHA
    • Branch name
    • Build timestamp
    • Package version
    • Custom environment variables you specify
  2. Exposes this information via a REST endpoint (default: /git-info):

{
  "version": "1.0.0",
  "githubSHA": "a1b2c3d4e5f6...",
  "githubBranch": "main",
  "buildTime": "2024-01-01T00:00:00.000Z"
}

This is particularly valuable when:

  • Debugging production issues and need to verify which code version is deployed
  • Managing multiple environments and need to track deployments

The module assumes you are using GitHub Actions, automatically capturing their environment variables during the build process.

Installation

npm install nest-git-info

Quick Start

  1. Install module in your code:
import { GitInfoModule } from 'nest-git-info';

@Module({ imports: [GitInfoModule.register()] })
export class AppModule {}
  1. Add a prebuild script (or to your existing prebuild script) so that the git environment details can be added at build time. By running this at build time, we avoid issues with docker cache layers in the npm install.
{
  "scripts": {
    "prebuild": "nest-git-info",
    "build": "nest build"
  }
}
  1. Add the build info file to your .gitignore:
src/build-info.json
  1. Make sure you have the following in your nest-cli.json to ensure the build info is compiled into the build output:
{
  "$schema": "https://json.schemastore.org/nest-cli",
  "collection": "@nestjs/schematics",
  "sourceRoot": "src",
  "compilerOptions": {
    "deleteOutDir": true,
    "assets": [
      "**/*.json"
    ]
  }
}

The prebuild script will automatically run before your build, generating the Git information file. This works in both local development and CI/CD environments. For local builds you will just see a development default value since the github environment variables wont exist.

Configuration

Module Options

GitInfoModule.register({
  // Controller configuration
  routePath: 'version',              // Default: 'git-info'
  swaggerTag: 'Version Info',        // Default: 'git-info'
  
  // Feature flags
  disableSwagger: false,             // Default: false
  disableController: false,          // Default: false
});

Async Configuration

GitInfoModule.registerAsync({
  useFactory: (configService: ConfigService) => ({
    disableController: configService.get('NODE_ENV') === 'production',
    routePath: configService.get('GIT_INFO_PATH'),
  }),
  inject: [ConfigService],
});

Environment Variables

The module uses environment variables for configuration:

  1. Git Information Variables (defaults):
  • GITHUB_SHA - The commit SHA
  • GITHUB_REF_NAME - The branch name
  1. Override Default Variable Names:
  • GIT_INFO_SHA_VAR - Override the SHA environment variable name
  • GIT_INFO_BRANCH_VAR - Override the branch environment variable name
  1. Additional Custom Variables:
  • GIT_INFO_ADD_* - Add custom environment variables to the output Example: GIT_INFO_ADD_ENVIRONMENT=NODE_ENV will add the NODE_ENV value to the output

Example Usage

Basic setup with GitHub Actions (uses default environment variables):

@Module({
  imports: [GitInfoModule.register()]
})
export class AppModule {}

Example Usage - Runtime Controller Configuration

While environment variables control the build information, you might want to configure how the API endpoint behaves at runtime. For this, use registerAsync:

@Module({
  imports: [
    ConfigModule.forRoot(),
    GitInfoModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        // Disable the controller in production
        disableController: configService.get('NODE_ENV') === 'production',
        // Use a custom endpoint path from configuration
        routePath: configService.get('GIT_INFO_PATH') || 'git-info',
        // Disable Swagger in production
        disableSwagger: configService.get('NODE_ENV') === 'production'
      }),
      inject: [ConfigService],
    }),
  ]
})
export class AppModule {}

This allows you to:

  • Configure the API endpoint path dynamically
  • Enable/disable the controller based on environment
  • Control Swagger documentation
  • Integrate with your application's configuration system (ConfigService, etc.)

Custom environment variables examples:

# In your CI/CD environment or .env file
GIT_INFO_SHA_VAR=CUSTOM_SHA
GIT_INFO_BRANCH_VAR=CUSTOM_BRANCH
GIT_INFO_ADD_ENVIRONMENT=NODE_ENV
GIT_INFO_ADD_REGION=AWS_REGION

API Response Example

{
  "version": "1.0.0",
  "githubSHA": "a1b2c3d4e5f6...",
  "githubBranch": "main",
  "buildTime": "2024-01-01T00:00:00.000Z",
  "ENVIRONMENT": "production",
  "REGION": "us-east-1"
}

GitHub Actions Integration

This package automatically works with GitHub Actions as it uses the default environment variables that GitHub Actions injects during builds:

  • GITHUB_SHA: The commit SHA that triggered the workflow
  • GITHUB_REF_NAME: The branch or tag name that triggered the workflow

For local development, these values will default to "development" if the environment variables aren't present.

Swagger Support

The module includes Swagger support out of the box if you have @nestjs/swagger installed. The endpoint will be automatically documented under the 'git-info' tag.

License

MIT