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

create-fastify-typescript

v1.0.5

Published

A starter for Fastify with TypeScript

Readme

create-fastify-typescript

中文

A Fastify + TypeScript project template for Node.js 24+. Create a new project with:

npm create fastify-typescript@latest my-project

Features

  • Fastify 5 + TypeScript with modern Node.js 24 output.
  • Environment configuration through @fastify/env.
  • Automatic loading for plugins/, decorators/, and routes/ through @fastify/autoload.
  • Built-in CORS, JWT, Redis, MySQL, rate limit, raw body, and EJS view plugins.
  • Example routes for one JSON endpoint and one HTML template endpoint.
  • Vite Plus workflows for vp test and vp check.

Quick Start

npm install
cp .env.example .env
npm run dev

The server listens on 0.0.0.0:3000 by default. Example endpoints:

  • GET /api/test returns JSON.
  • GET /test renders HTML through EJS.

Scripts

npm run dev      # run TypeScript source with Node 24 watch mode
npm run build    # compile to dist/ and copy templates/
npm start        # run dist/server.js
npm test         # run tests with vp test
npm run check    # run format, lint, and type checks with vp check

Project Structure

.
├── app.ts              # creates Fastify, registers env, and autoloads folders
├── server.ts           # starts the server from fastify.config
├── config/             # environment variable schema
├── decorators/         # Fastify decorators, autoloaded
├── plugins/            # infrastructure plugins, autoloaded
├── routes/             # route entry points, autoloaded
├── services/           # service-layer code
├── templates/          # EJS templates
├── tests/              # Vite Plus tests
├── types/              # Fastify module augmentation
└── utilities/          # shared utility functions

Environment

The configuration schema lives in config/env.ts. Copy .env.example to .env, then update database, Redis, JWT, and other environment-specific values.

ALIAS defines the project namespace and defaults to jealer. For example, decorators/userAuth.ts uses it to create Redis token cache keys:

${ALIAS}:user_token:${userId}

MySQL and Redis are disabled by default so the template can start without local infrastructure. Enable them only when the project needs those services:

MYSQL_ENABLED=true
REDIS_ENABLED=true

CORS_ORIGIN controls @fastify/cors. Use * for open development access, false to disable CORS origins, or a comma-separated list for multiple origins:

CORS_ORIGIN=https://example.com,https://admin.example.com

Autoloading

app.ts uses @fastify/autoload for:

  • plugins/: CORS, MySQL, Redis, JWT, rate limit, raw body, view engine, and other infrastructure.
  • decorators/: for example fastify.authenticate.
  • routes/: all route files.

For new business code, add routes/{business}.ts and services/{business}.ts. Most features should not require changes to app.ts.

Utilities

Shared, framework-light helper functions live in utilities/. Keep utilities small and deterministic so they can be reused from plugins, decorators, routes, and services without creating Fastify coupling.

The template includes utilities/cache.ts:

import { createCacheKey } from './utilities/cache.ts';

const cacheKey = createCacheKey('jealer', 'user_token', userId);

Use this style for formatting cache keys, IDs, dates, payload normalization, and other cross-cutting helpers. Business logic should stay in services/, while reusable mechanics belong in utilities/.

Scaling Business Modules

The template starts with routes/ and services/ because that structure is simple and easy to scan. When the project grows past roughly 10 business areas, move complex features into module folders:

modules/
└── license/
    ├── routes.ts
    ├── service.ts
    ├── schema.ts
    └── repository.ts

Keep small features in routes/ and services/. Move a feature to modules/{feature}/ when its routes, services, schemas, repositories, or internal helpers become easier to maintain together.

Template Rendering

Templates live in templates/ and currently use EJS. Routes can return HTML directly:

fastify.get('/test', async (_request, reply) => {
  return reply.view('home', {
    heading: 'Fastify TypeScript',
    message: 'HTML rendering is ready.',
    title: 'Fastify TypeScript',
  });
});

Deployment

Deploy the dist/ directory to production environment after building the project with npm run build.