This project is a server application built using Fastify and pnpm. It is designed to provide a robust and scalable API with various endpoints for user management.
- 📚 Table of Contents
- 📁 Folder Structure
- 🔍 What Each Folder Does
- 🛠️ Getting Started
- 📜 Available Scripts
- 🚀 Deployments
- 👥 Contributors
- 📄 License
└── 📁fastify
└── 📁api
└── index.js
└── 📁src
└── app.ts
└── 📁assets
└── logo.svg
└── index.ts
└── 📁models
└── user.model.ts
└── 📁plugins
└── env.ts
└── mongo.ts
└── swagger.ts
└── 📁routes
└── user.routes.ts
└── 📁services
└── user.service.ts
└── 📁types
└── env.d.ts
└── mongo.d.ts
└── .env
└── .gitignore
└── LICENSE
└── package.json
└── pnpm-lock.yaml
└── readme.md
└── tsconfig.json
└── vercel.json
Folder/File | Purpose |
---|---|
models/ |
Define the database schema for user entities. |
plugins/ |
Register and configure various plugins such as environment variables and MongoDB. |
routes/ |
Register API routes with Fastify, defining endpoint handlers. |
services/ |
Implement business logic and perform database queries. |
types/ |
Provide type definitions for TypeScript, including custom Fastify extensions. |
index.ts |
Entry point of the application: imports and registers all routes and plugins, and starts the server. |
app.ts |
Sets up and configures the Fastify instance, making it ready for testing or deployment. |
-
Clone the repository:
git clone https://github.com/rayan25nov/Fastify-Server.git cd Fastify-Server
-
Install dependencies:
pnpm install
-
Create a
.env
file in the root directory with the following content:PORT="8080" MONGO_URI="mongodb://localhost:27017/user" BASE_URL="http://localhost:8080"
Run the following command to start the server in development mode with hot-reloading enabled:
pnpm dev
Script | Description |
---|---|
pnpm build |
Compiles the TypeScript code into JavaScript. |
pnpm start |
Starts the server using the compiled JavaScript files. |
pnpm dev |
Runs the server in development mode with TypeScript compilation and hot-reloading. |
pnpm test |
Runs the test suite using Jest. |
pnpm test:watch |
Runs the tests in watch mode for continuous testing during development. |
This project is deployed to Vercel using a serverless function. The serverless function is defined in api/index.js
, and the deployment configuration is specified in vercel.json
.
This project is licensed under the ISC License.