Skip to content

firadfd/express-app-learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

✅ Final README.md for express-app-learning

Express App Learning

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.


🚀 Features

  • User authentication with JWT
  • CRUD operations (e.g., Todo management)
  • MongoDB with Mongoose
  • Modular and clean folder structure
  • Environment-based configuration

📁 Project Structure

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

📦 Installation

  1. Clone the repository
git clone https://github.com/firadfd/express-app-learning.git
cd express-app-learning
  1. Install dependencies and Build Project
npm install
npm i
npm run build
  1. Create a .env file
PORT=5000
MONGO_URI=your_mongodb_connection
JWT_SECRET=your_jwt_secret_key

▶️ Running the App

  • For development with auto-reload: npm run dev

  • For production:

npm run dev

📡 API Endpoints

All routes are prefixed with /api/v1.

🔐 Auth Routes

POST /api/v1/auth/signup

Register a new user.

Body:

{
"name": "John",
"email": "john@example.com",
"password": "secret123"
}

POST /api/v1/auth/login

Log in an existing user.

Body:

{
"email": "john@example.com",
"password": "secret123"
}

📝 Todo Routes

GET /api/v1/todos

Get all todos for the authenticated user.

POST /api/v1/todos

Create a new todo.

Body:

{
  "title": "Learn Express",
  "description": "Build a backend app"
}

PUT /api/v1/todos/:id

Update an existing todo.

Body:

{
  "title": "Updated Title",
  "description": "Updated description"
}

DELETE /api/v1/todos/:id

Delete a todo by its ID.


🔐 Auth Middleware

To access protected routes like /api/v1/todos, add the JWT token to your Authorization header:

Authorization: <your_token>

⚙️ Environment Variables

| Key        | Description                |
| ---------- | -------------------------- |
| PORT       | 3000                       |
| MONGO_URI  | MongoDB connection string  |
| JWT_SECRET | Secret key for JWT signing |

👨‍💻 Author

MD. Firaduzzaman

Flutter Developer & Backend Learner


📄 License

MIT License

If you want, I can **add Postman examples**, or convert this to Bengali or Markdown with emojis. Just say the word!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors