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

build-info

v1.0.0

Published

Looks for a version information file and returns the result via an Express route

Downloads

16

Readme

build-info

Provides middleware for publishing app version information as a REST API.

build-version is a piece of middleware that works with Express to expose the current application build level as an API. Though it hasn't been tested, it should work with other Node.js web app frameworks that use the same syntax as Express middleware.

Usage

As part of your build process, output a file to the root of your application called versionInfo.json. The format of this file should (hopefully obviously) be JSON. If the JSON is malformed, build-version will display an error when its registered route is called.

To get this up and running quickly, set up your main app script something like this:

The versionInfo file can be of any format you prefer. Here's an example:

{
    "buildid" : "2016-03-14_20-10-33",
    "repository" : "my-webapp",
    "branch" : "feature/apiv2",
    "timestamp" : "20160314160734",
    "docker" : {
        "image" : "product_my-webapp",
        "tag" : "98dac66"
    }
}

From that point, set up your web app to include the build-version middleware and assign it a route, something like this:

var express = require('express');
var app = express();
var buildInfo = require('build-info');

...

app.get('/build-info', buildInfo());

buildVersion() optionally accepts an object argument, allowing you to specify some properties:

  • filePath - Accepts a relative or absolute path string if the versionInfo.json file is located somewhere other than the current working directory.
  • fileName - Accepts a string allowing the target JSON file to be named something other than versionInfo.json.
  • deployment - Accepts an object for setting values at runtime that are specific to the application's deployment.
  • metadata - Accepts an object for setting additional properties not covered by other fields.

Once you start your app, invoke your route via GET /build-info. The output should look something like this (based on what you put in your versionInfo file.

{
    "statusCode": 200,
    "buildid" : "2016-03-14_20-10-33",
    "repository" : "my-webapp",
    "branch" : "feature/apiv2",
    "timestamp" : "20160314160734",
    "docker" : {
        "image" : "product_my-webapp",
        "tag" : "98dac66"
    }
}

If anything goes wrong when reading your file, statusCode will be set to 404 (file not found) or 500 (something else went wrong, like a JSON parse failure). A message property will also be added to the response explaining what happened.