Skip to content

Latest commit

Β 

History

History
114 lines (84 loc) Β· 3.2 KB

File metadata and controls

114 lines (84 loc) Β· 3.2 KB

Starter Fastify API

A Node.js TypeScript project with Fastify to create a performant and modern API.

πŸš€ Features

  • Fastify : Fast and efficient web framework for Node.js
  • TypeScript : Static typing and modern development
  • ESModule : Native ES6 modules support
  • JWT Authentication : JWT authentication support
  • CORS : Cross-Origin Resource Sharing support
  • Cookie Support : Built-in cookie management
  • ESLint : Linting with latest TypeScript rules
  • Prettier : Automatic code formatting
  • Hot Reload : Automatic reload in development with tsx

πŸ“‹ Prerequisites

  • Node.js 18+
  • npm or yarn

πŸ› οΈ Installation

npm install

🚦 Available Scripts

  • npm run dev - Start the server in development mode with hot reload
  • npm run build - Compile TypeScript to JavaScript
  • npm start - Start the server in production mode
  • npm run lint - Check code with ESLint
  • npm run lint:fix - Automatically fix ESLint errors
  • npm run format - Format code with Prettier
  • npm run type-check - Check TypeScript types without compilation

πŸƒβ€β™‚οΈ Quick Start

Development mode

npm run dev

Production mode

npm run build
npm start

πŸ“‘ Available Endpoints

Main API

  • GET /api - API root endpoint with version information

Status

  • GET /api/status - API status with uptime

Authentication

  • POST /api/auth/signup - Sign up (not implemented)
  • POST /api/auth/signin - Sign in (not implemented)
  • POST /api/auth/logout - Logout (not implemented)

πŸ”§ Configuration

The server can be configured via the .env file at the project root and the config folder in the src directory.

πŸ“ Project Structure

starter-fastify-api/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # Main entry point with FastifyAPIStarter class
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── index.ts          # Server configuration
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   └── index.ts      # Authentication routes
β”‚   β”‚   β”œβ”€β”€ index/
β”‚   β”‚   β”‚   └── index.ts      # Main API route
β”‚   β”‚   └── status/
β”‚   β”‚       └── index.ts      # Status route
β”‚   └── types/
β”‚       └── index.ts          # TypeScript types
β”œβ”€β”€ dist/                     # Compiled code (generated)
β”œβ”€β”€ .prettierrc              # Prettier configuration
β”œβ”€β”€ .prettierignore          # Files ignored by Prettier
β”œβ”€β”€ eslint.config.js         # ESLint configuration (v9)
β”œβ”€β”€ tsconfig.json            # TypeScript configuration
└── package.json             # Dependencies and scripts

🧰 Technologies Used

  • Node.js - JavaScript runtime
  • Fastify 5 - Ultra-fast web framework
  • TypeScript - Programming language
  • @fastify/jwt - JWT plugin for authentication
  • @fastify/cors - CORS plugin
  • @fastify/cookie - Cookie support
  • ESLint 9 - Linter with flat config configuration
  • Prettier 3 - Code formatter
  • tsx - TypeScript runtime for development

License

This project is distributed under the GNU General Public License v3.0.

See the LICENSE file for more information.