A powerful and modular Fastify-based backend boilerplate featuring secure authentication, PostgreSQL database management with Drizzle ORM, and automated Swagger documentation.
- Fastify Framework: High-performance, low-overhead web framework.
- Authentication: JWT-based security with password hashing via
bcrypt. - Drizzle ORM: Type-safe and lightweight ORM for PostgreSQL.
- Swagger Documentation: Interactive API testing interface at
/docs. - Environment Management: Flexible configuration using
.env. - Pretty Logging: Colorful and minimal logs in development using
pino-pretty.
- Runtime: Node.js (v20+)
- Server: Fastify
- Database: PostgreSQL
- ORM: Drizzle ORM
- Security: @fastify/jwt,
bcrypt - Documentation: @fastify/swagger
-
Clone the repository:
git clone https://github.com/emranweb/node-fastify.git cd node-fastify -
Install dependencies:
yarn install # or npm install -
Setup Environment Variables: Create a
.envfile in the root directory and add your credentials:PORT=4000 DATABASE_URL=postgresql://user:password@localhost:5432/db_name JWT_SECRET=your_super_random_secret_here
Ensure your PostgreSQL server is running. Use Drizzle Kit to push your schema to the database:
npx drizzle-kit pushyarn devyarn startOnce the server is running, you can access the interactive Swagger documentation at:
http://localhost:4000/docs
POST /auth/register: Create a new user account.POST /auth/login: Authenticate and receive a JWT token.GET /users/me: (Protected) Get current user profile data.
To access protected routes (/users/*), you must include the JWT token in the request header:
Authorization: Bearer <YOUR_TOKEN>
This project is ISC licensed.