A beginner-friendly RESTful API built with Node.js, Express, and MongoDB. This project demonstrates how to structure a basic backend application using controllers, routes, middleware, and environment configuration.
- User authentication with JWT
- CRUD operations (e.g., Todo management)
- MongoDB with Mongoose
- Modular and clean folder structure
- Environment-based configuration
express-app-learning/
│
├── src/ # Source code
│ ├── module/ # Feature-based modules
│ │ ├── auth/ # Auth module
│ │ │ ├── auth.routes.ts # Auth routes
│ │ │ └── auth.service.ts # Auth service logic
│ │ └── todo/ # Todo module
│ │ ├── todo.controller.ts # Todo controller (request handlers)
│ │ ├── todo.routes.ts # Todo routes
│ │ └── todo.service.ts # Todo service (business logic)
│ │
│ ├── routes/
│ │ └── routes.ts # Combine and register all routes
│ │
│ ├── schema/
│ │ ├── todoSchema.ts # Todo Mongoose schema
│ │ └── userSchema.ts # User Mongoose schema
│ │
│ ├── shared/ # Shared utilities/helpers
│ │ ├── catchAsync.ts # Async error handler
│ │ ├── paginations.ts # Pagination utility
│ │ ├── sendResponse.ts # Standardized API response
│ │ └── handler.ts # Global error handler
│ │
│ └── app.ts # Express app setup
│
├── dist/ # ⛔ Auto-generated compiled JS files after build
│ # (Do not edit manually)
│
├── .env # Environment variables
├── .gitignore # Files to ignore in git
├── nodemon.json # Nodemon configuration
├── package.json # Project metadata and scripts
├── tsconfig.json # TypeScript configuration
├── vercel.json # Vercel deployment configuration
├── yarn.lock / package-lock.json # Dependency lock files
└── README.md # Project overview and instructions- Clone the repository
git clone https://github.com/firadfd/express-app-learning.git
cd express-app-learning- Install dependencies and Build Project
npm install
npm i
npm run build- Create a .env file
PORT=5000
MONGO_URI=your_mongodb_connection
JWT_SECRET=your_jwt_secret_key-
For development with auto-reload: npm run dev
-
For production:
npm run devAll routes are prefixed with
/api/v1.
Register a new user.
Body:
{
"name": "John",
"email": "john@example.com",
"password": "secret123"
}Log in an existing user.
Body:
{
"email": "john@example.com",
"password": "secret123"
}Get all todos for the authenticated user.
Create a new todo.
Body:
{
"title": "Learn Express",
"description": "Build a backend app"
}Update an existing todo.
Body:
{
"title": "Updated Title",
"description": "Updated description"
}Delete a todo by its ID.
To access protected routes like /api/v1/todos, add the JWT token to your Authorization header:
Authorization: <your_token>
| Key | Description |
| ---------- | -------------------------- |
| PORT | 3000 |
| MONGO_URI | MongoDB connection string |
| JWT_SECRET | Secret key for JWT signing |MD. Firaduzzaman
Flutter Developer & Backend Learner
MIT License
If you want, I can **add Postman examples**, or convert this to Bengali or Markdown with emojis. Just say the word!