@ynode/versionify
v1.3.2
Published
Fastify 5 plugin that exposes application name and version via a RESTful endpoint with content negotiation, cache control, and structured metadata.
Maintainers
Readme
@ynode/versionify
Copyright (c) 2025 Michael Welter [email protected]
A simple and lightweight Fastify plugin to expose your application's name and version from package.json.
It automatically handles content negotiation to respond with JSON, HTML, or plain text based on the client's Accept header.
Installation
Install the package and its required peer dependency, fastify.
npm install @ynode/versionify fastify
Options
You can pass an options object as the second argument to register.
| Option | Type | Default | Description |
| :-- | :-- | :-- | :-- |
| prefix | string | undefined | Optional Fastify route prefix. |
| path | string | "/version" | The URL path to expose the version endpoint. |
| pkg | object | undefined | A package.json object. If not provided, the plugin will automatically load package.json from your project root. |
| cacheMaxAge | number | 3600 | Cache-Control max-age in seconds. Set to 0 to disable. |
| metadata | object | undefined | Additional static key-value pairs included in the JSON response. Keys name and version are reserved and will be ignored. |
Basic Usage
import versionify from "@ynode/versionify";
// Register the plugin with default options
await fastify.register(versionify, { prefix: "/~" });Example with Options
import versionify from "@ynode/versionify";
// Register with a custom path
await fastify.register(versionify, {
path: "/info",
});Now the endpoint will be available at http://localhost:3000/info.
Example with Metadata and Cache Control
import process from "node:process";
import versionify from "@ynode/versionify";
await fastify.register(versionify, {
metadata: { environment: "production", nodeVersion: process.version },
cacheMaxAge: 7200,
});The JSON response will include all metadata fields alongside name and version:
{
"name": "my-app",
"version": "2.1.0",
"environment": "production",
"nodeVersion": "v22.0.0"
}License
This project is licensed under the MIT Lisence.
