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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xenterprises/fastify-xconfig

v2.3.0

Published

Fastify configuration plugin for setting up middleware, services, and route handling.

Downloads

80

Readme

xConfig

Core infrastructure plugin for Fastify. Composes CORS, rate limiting, multipart, under-pressure monitoring, Bugsnag error tracking, Prisma, a /health route, formatted error handling, and small utility decorators into a single registration.

Install

npm install @xenterprises/fastify-xconfig fastify@5
# if using Prisma:
npm install @prisma/client

Minimal example

import Fastify from "fastify";
import xConfig from "@xenterprises/fastify-xconfig";

const fastify = Fastify();

// Bare registration works — Prisma and Bugsnag are opt-in
await fastify.register(xConfig, {
  environment: process.env.NODE_ENV, // plugin never reads env itself
});

Options

All configuration is passed at registration. The plugin never reads process.env.

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | environment | string | no | "development" | Drives stack traces in error responses and the /health payload | | professional | boolean | no | false | Suppress the startup route listing | | fancyErrors | boolean | no | true | Enable the formatted error handler | | prisma | object | no | {} (disabled) | Omit to leave Prisma disabled; { client } enables it (class or instance); active: false also disables | | prisma.client | PrismaClient class or instance | when prisma.active: true | — | Your generated client. Pass the class and the plugin instantiates it with the remaining prisma.* options, or pass an instance you created | | bugsnag | object | no | {} (disabled) | Omit to leave Bugsnag disabled; { apiKey } enables it; active: false also disables | | bugsnag.apiKey | string | when bugsnag.active: true | — | Bugsnag API key | | cors | object | no | localhost origins | @fastify/cors options plus active: false to disable | | rateLimit | object | no | @fastify/rate-limit defaults | Same, pass max/timeWindow to configure | | multipart | object | no | @fastify/multipart defaults | Same | | underPressure | object | no | @fastify/under-pressure defaults | Same |

Every middleware option bag accepts active: false to skip that middleware entirely.

CORS defaults are localhost-only (http://localhost:3000, http://localhost:3001, credentials on). Deployed apps MUST pass cors.origin explicitly.

Decorators

Utilities live under a single fastify.xConfig namespace:

| Decorator | Description | |-----------|-------------| | fastify.xConfig.echo() | Returns "Hello from X Enterprises!" | | fastify.xConfig.slugify(string) | URL-safe slug | | fastify.xConfig.randomUUID() | Random UUID | | fastify.xConfig.generateUUID() | Random UUID (alias of randomUUID) | | fastify.xConfig.formatBytes(bytes, decimals?) | Human-readable byte sizes |

Integration decorators (only when that integration is enabled):

| Decorator | Description | |-----------|-------------| | fastify.prisma | PrismaClient (only when prisma.client is provided) | | fastify.bugsnag | Bugsnag client (only when bugsnag.apiKey is provided) |

Also registers @fastify/sensible, so its decorators (reply.notFound(), fastify.httpErrors, …) are available.

Routes

| Method | Path | Description | |--------|------|-------------| | GET | /health | Health check: status, uptime, environment, DB/Redis connectivity (when decorated), memory/CPU/disk usage. Returns 200 when healthy, 503 when degraded |

Error behavior

Registration fails fast — messages name the plugin, the option, and show a correct example:

  • prisma: { active: true } without prisma.client, or prisma.client is neither a class nor an instance
  • bugsnag: { active: true } without bugsnag.apiKey, or bugsnag.apiKey is not a string
  • environment, professional, or fancyErrors have the wrong type

With fancyErrors enabled (default), route errors are returned as { status, message, stack? }; stack is included only when environment is not "production". With fancyErrors: false, Fastify's default error handler is used.

Requirements

  • Node.js >= 20
  • Fastify ^5.0.0 (peer dependency)
  • When Prisma is active: your own generated @prisma/client (the plugin never imports it — you pass the client in)

License

Proprietary — All Rights Reserved X Enterprises. See LICENSE.