To execute this example, install Node.js and Docker. The local workflow below starts MongoDB and Mailpit for you in Docker.
- Node.js 22+
- Latest Docker engine
-
Build the Docker Image:
docker build -t fastify-boilerplate . -
Start the Docker Containers:
docker-compose -f docker/docker-compose-test.yml up
-
Install Dependencies:
npm install
-
Create the local env file:
make init-envmake init-env creates .env with local-safe defaults and generates when opensslis available. If.env` already exists, the target leaves it unchanged.
-
Adjust
.envif needed:Leave
SMTP_HOST,SMTP_PORT,SMTP_SECURE,SMTP_USER, andSMTP_PASSunset to use local Mailpit by default. Review or rotate the generated secrets before reusing the environment elsewhere. -
Start the local stack:
make dev
This starts MongoDB on
localhost:27017, Mailpit SMTP onlocalhost:1025, and the Mailpit inbox UI onhttp://localhost:8025. -
Inspect captured email in Mailpit:
Open
http://localhost:8025and trigger flows such as password reset. Development defaults to Mailpit unless you set real SMTP credentials in.env. -
Run Tests:
npm run test -
Stop the local containers when finished:
make dev-stop
For short manual delivery checks, add the SMTP settings below to .env and rerun make dev:
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-smtp-user
SMTP_PASS=your-smtp-passwordOutside development and test, the app now fails fast during boot if SMTP is not configured.
-
Create
.envonce for local development:make init-env
-
Start local MongoDB + Mailpit + app:
make dev
-
Stop local MongoDB + Mailpit:
make dev-stop
-
Run database migrations with
.envloaded:make migrate
-
Run tests:
make test -
Run lint:
make lint