The aim of this repository is to provide a concrete example of a Fastify application using what are considered best practices by the Fastify community.
Prerequisites: You need to have Node.js version 22 or higher installed.
This demo is a simple task management API. It allows users to create, retrieve, update, and delete tasks. Additional features include file uploads, CSV downloads, task assignment, and role-based access control.
Install the dependencies:
npm installYou can run a MySQL instance with Docker:
docker compose upTo run it in the background:
docker compose up -dTo create the database, run:
npm run db:createTo create and update the database schema, run the migrations:
npm run db:migrateTo populate the database with initial data, run:
npm run db:seedTo drop the database, run:
npm run db:dropTo build the project:
npm run buildIn dev mode:
npm run devOpen http://localhost:3000 to view it in the browser.
In production mode:
npm run startThe application exposes interactive API documentation using Swagger UI.
Once the server is running, visit: http://localhost:3000/api/docs
To run the tests:
npm run testdev and start leverage fastify-cli,
but you can run the demo as a standalone executable (see server.ts):
npm run standaloneTo check for linting errors:
npm run lintTo check and automatically fix linting errors:
npm run lint:fixTo learn more about Fastify, check out the Fastify documentation.