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

@authuser/nest-fastify-kit

v0.1.8

Published

Reusable NestJS + Fastify HTTP foundation kit

Downloads

848

Readme

npm version npm downloads npm bundle size license node nestjs fastify


Table of contents

Features

  • Fast bootstrap with NestFactory + FastifyAdapter
  • Strongly typed app options (CreateHttpAppOptions)
  • Secure defaults with configurable presets
  • Global validation, filters, and interceptors
  • Nest native logging
  • Request ID propagation via request context
  • Optional Swagger docs and health endpoints
  • Minimal configuration, extensible architecture

Installation

npm install @authuser/nest-fastify-kit

Peer dependencies expected in your app:

  • @nestjs/common ^11
  • @nestjs/core ^11
  • @nestjs/platform-fastify ^11
  • fastify ^5
  • class-transformer ^0.5
  • class-validator ^0.14
  • reflect-metadata
  • rxjs

Optional peer dependencies (for optional features):

  • @nestjs/config
  • @nestjs/swagger
  • @nestjs/terminus

Quick start

import { createHttpApp } from '@authuser/nest-fastify-kit';
import { AppModule } from './app.module';

async function bootstrap() {
	const app = await createHttpApp({
		rootModule: AppModule,
		appName: 'users-api',
		preset: 'secure',
		apiPrefix: 'api',
		apiVersioning: true,
		docs: process.env.NODE_ENV !== 'production',
	});

	await app.listen(3000, '0.0.0.0');
}

void bootstrap();

Public API

export { createHttpApp } from './bootstrap/create-http-app';
export { Public } from './security/auth/decorators/public.decorator';
export { Roles } from './security/auth/decorators/roles.decorator';
export * from './types/create-http-app-options';

createHttpApp(options)

Creates and configures a NestFastifyApplication with common production defaults.

createHttpApp(options: CreateHttpAppOptions): Promise<NestFastifyApplication>

Configuration

interface CreateHttpAppOptions {
	rootModule: unknown;
	appName: string;

	preset?: 'minimal' | 'secure' | 'full';

	apiPrefix?: string;
	apiVersioning?: boolean;

	docs?: boolean;

	config?: {
		enabled?: boolean;
		isGlobal?: boolean;
		ignoreEnvFile?: boolean;
		envFilePath?: string | string[];
		validate?: (config: Record<string, unknown>) => Record<string, unknown>;
	};

	cors?: {
		origin: string[] | boolean;
		credentials?: boolean;
	};

	security?: {
		helmet?: boolean;
		csp?: boolean;
		hidePoweredBy?: boolean;
		rateLimit?: {
			max: number;
			timeWindow: string;
			excludePaths?: string[];
		};
	};

	network?: {
		trustProxy?: boolean | string | number;
	};

	auth?: {
		enabled?: boolean;
		userProperty?: string;
	};

	lifecycle?: {
		shutdownHooks?: boolean;
	};

	observability?: {
		logger?: {
			level?: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
		};
		requestLogging?: boolean;
		startupLog?: boolean;
		metrics?: boolean;
		tracing?: boolean;
	};
}

Full options reference and defaults are documented in:

Presets

minimal

  • Fastify adapter
  • Global validation
  • Logging setup

secure (default)

  • Everything in minimal
  • Helmet
  • Rate limiting
  • Built-in rate-limit exclusions for /health and /docs
  • Strict CORS default (origin: false) if cors is not provided
  • x-powered-by header removal

full

  • Everything in secure
  • Swagger enabled by default (docs: true)
  • Health module enabled by default
  • Metrics flag enabled by default (observability.metrics: true)

Advanced guide

Detailed runtime behavior and advanced recipes are available in:

TypeScript support

This package is built with strict TypeScript settings and publishes declaration files (dist/*.d.ts).

Security notes

  • Security defaults are opinionated but not universal.
  • Helmet Content Security Policy is enabled by default (security.csp: true).
  • Set security.csp: false only when a specific integration requires a temporary relaxation.
  • Always validate CORS origins for your environment.
  • Tune rate limiting based on traffic profile and endpoint sensitivity.
  • Keep dependencies updated in consuming services.

FAQ

Does this replace NestJS app architecture?

No. It standardizes HTTP bootstrap concerns but keeps Nest modules, providers, controllers, and DI patterns intact.

Can I disable built-in features?

Yes. Use preset: 'minimal' or override specific options (security.helmet, security.rateLimit, docs, etc.).

Can I still register my own Fastify/Nest plugins?

Yes. createHttpApp returns a regular NestFastifyApplication.

Can I customize middleware, proxy behavior, and hooks?

Yes.

  • Configure proxy trust with network.trustProxy.
  • Register your own Fastify plugins/hooks after createHttpApp(...) and before app.listen(...).
  • Add regular Nest customizations (global interceptors, filters, pipes, guards) on the returned app instance.
const app = await createHttpApp({
	rootModule: AppModule,
	appName: 'users-api',
	network: { trustProxy: true },
});

const fastify = app.getHttpAdapter().getInstance();
await fastify.register(myFastifyPlugin);
fastify.addHook('onRequest', myOnRequestHook);

app.useGlobalInterceptors(new MyInterceptor());

await app.listen(3000, '0.0.0.0');

Contributing

npm install
npm run test
npm run typecheck
npm run build

License

MIT