Skip to content

A robust and modern starter template for building high-performance web applications using Fastify, TypeScript, and Drizzle ORM

License

Notifications You must be signed in to change notification settings

tinchoz49/fastify-starter

Repository files navigation

Fastify TypeScript Starter

A robust and modern starter template for building high-performance web applications using Fastify, TypeScript, and Drizzle ORM.

Node.js version. If you are looking to use this template with Bun go to Bun Starter

🚀 Features

  • Fastify: High-performance web framework for Node.js
  • TypeScript: Strongly typed programming language that builds on JavaScript
  • Fastify UWS: Push your Fastify server performance to the next level
  • Drizzle ORM: TypeScript ORM for SQL databases with a focus on type safety
  • PostgreSQL: Powerful, open-source relational database
  • node:test: Built-in testing framework for Node.js
  • pglite: In-memory PostgreSQL database for testing
  • Standard Ext: JavaScript style guide, linter, and formatter
  • Typebox: JSON schema based validation and generation
  • Copycat: Deterministic data generation for testing and seeding
  • typebox-env: Environment variables parsing and validation

Fastify Plugins

🧰 Commands

  • npm run dev: Start the development server.
  • npm run build: Build the application.
  • npm run start: Start the application.
  • npm run test: Run the test cases.
  • npm run coverage: Generate the coverage report.
  • npm run lint: Run the linter.
  • npm run db:generate: Generate the migration file.
  • npm run db:migrate: Apply the migration to the database.
  • npm run db:check: Check the migration file.

📁 Structure

  • src/: Source code.
  • src/app.ts: Fastify application.
  • src/serve.ts: Entry point.
  • src/env.ts: TypeBox schema for environment variables.
  • src/errors.ts: Custom errors.
  • src/plugins/: User defined Fastify plugins.
  • src/routes/: Fastify API routes.
  • src/schemas/: TypeBox schemas.
  • src/db/: Drizzle ORM.
  • dist/: Build output.
  • test/: Test cases.
  • migrations/: Drizzle migrations.

Development

Start by creating a new .env file and setting the correct environment variables.

cp .env.example .env.development
# Node environment: development, production, or test
NODE_ENV=development

# Server host
HOST=127.0.0.1

# Server port
PORT=3000

# Log level (optional): info, error, debug, fatal, warn, trace, child
LOG_LEVEL=info

# Database configuration

DATABASE_URL=postgresql://localhost:5432/db

# For in-memory database:
DATABASE_RUN_IN_MEMORY=true

# Database operations
DATABASE_RUN_SEED=true
DATABASE_RUN_MIGRATE=true

# JWT configuration
JWT_SECRET=your_jwt_secret_key
# JWT_CACHE=false
# JWT_CACHE_TTL=60000

# OpenAPI configuration
OPENAPI_ENABLED=true
OPENAPI_UI=true
$ npm run dev

Issues

🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

License

MIT © 2024 Martin Acosta

About

A robust and modern starter template for building high-performance web applications using Fastify, TypeScript, and Drizzle ORM

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published