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

mkver

v4.3.1

Published

Node.js access to your app's version and release metadata

Downloads

1,278

Readme

Easy access to your version and build metadata from within Node.js

npm version Build & Release CodeQL

Why?

Simple, reliable access to version and build information from within Node.js and Electron apps should be easy, without runtime dependencies.

Even if you push git SHAs into your package.json, after minification, asarification, and installation into platform-specific directory structures, you'll still be fighting __dirname bugs trying to find where your package.json went.

In TypeScript and ES6 module environments, there's a simple, minification-compatible and asar-compatible solution for importing information from outside your current file.

It's called import. Or for CommonJS users, require.

By writing build-specific information as constants in code within our codebase, consuming this metadata becomes trivial. Add it to your build pipeline, import it, and focus on the big problems.

What?

mkver produces either:

Each file contains your git SHA and version information exported as constants.

Example output

// Version.ts

export const version = "1.2.3-beta.4";
export const versionMajor = 1;
export const versionMinor = 2;
export const versionPatch = 3;
export const versionPrerelease = ["beta", 4];
export const release = "1.2.3-beta.4+20220101105815";
export const gitSha = "dc336bc8e1ea6b4e2f393f98233839b6c23cb812";
export const gitDate = new Date(1641063495000);
export default {
  version,
  versionMajor,
  versionMinor,
  versionPatch,
  versionPrerelease,
  release,
  gitSha,
  gitDate,
};

The filename can be anything you want as long as the file extension is:

  • .ts,
  • .mjs,
  • .js, or
  • .cjs.

It also creates a SemVer-compatible release field in the format ${version}+${YYYYMMDDhhmmss of gitDate}, and a gitDate Date instance representing when the last git commit occurred.

Module Format

mkver itself is distributed as a CommonJS package to ensure maximum compatibility across different Node.js environments and platforms. While the tool internally uses ES modules during development, the distributed package uses CommonJS to avoid compatibility issues that can arise with ESM on certain platforms (particularly Windows).

However, mkver generates output files in whatever format you need:

  • TypeScript (.ts) with ES module exports
  • ES modules (.mjs) with ES module exports
  • CommonJS (.js or .cjs) with CommonJS exports

The output format is determined solely by the file extension you specify.

Installation

Step 1: Add mkver to your package.json

npm i --save-dev mkver

Step 2: For TypeScript users

Add a pre... npm script to your package.json that runs mkver:

  "scripts": {
    ...
    "precompile": "mkver",
    "compile": "tsc",
    ...
  }

Step 2: For JavaScript module or CommonJS users

Add mkver as a pre... script for your test script and/or build pipeline in your package.json:

  "scripts": {
    ...
    "prebuild": "mkver ./lib/version.mjs", // or ./lib/version.js or ./lib/version.cjs
    "build": "webpack", // or whatever you use
    ...
  }

Step 3: Add to .gitignore

You should add your Version.ts, version.mjs, version.js, or version.cjs file to your project's .gitignore.

Usage

mkver [FILE]

Where FILE is optional and defaults to ./Version.ts.

CLI Options

  • -h, --help - Show help message
  • -v, --version - Show version number

Examples

# Generate Version.ts (default)
mkver

# Generate a specific file
mkver ./src/version.mjs

# Show version
mkver --version

# Show help
mkver --help

How

mkver is a simple, dependency-free, three-step tool:

  1. mkver recursively searches for a package.json starting from the current directory and extracts the version value.
  2. mkver executes git rev-parse HEAD to get the last commit SHA. Git must be available in your PATH.
  3. mkver writes the output to the specified file (default: ./Version.ts). The file extension determines the output format (TypeScript, ESM, or CommonJS). Existing files will be overwritten.

If anything goes wrong, mkver will output (hopefully) helpful error messages to stderr and exit with a non-zero code.

Use with TypeScript or MJS modules

import { version, release } from "./Version";

Use with CommonJS

const { version, release } = require("./version"); // Ensure the case matches your mkver output filename

Remember to specify mkver version.js (or version.cjs) in your npm script (see Installation Step 2 above).

Bash access to your version info

Need access to your release from a bash deploy script?

  # For CommonJS (.js or .cjs files):
  release=$(node -e "console.log(require('./path/to/version.js').release)")

  # For ESM (.mjs or .ts files):
  release=$(node -e "import('./path/to/version.mjs').then(m => console.log(m.release))")

Changelog

See CHANGELOG.md.