ashishpathak2 / Cactro-backend-crud

API Development and Deployment for a Task Management Backend

Home Page:https://cactro-backend-crud.onrender.com

Repository from Github https://github.comashishpathak2/Cactro-backend-crudRepository from Github https://github.comashishpathak2/Cactro-backend-crud

πŸš€ Cactro Backend CRUD –


🧠 Project Structure

src/
β”œβ”€β”€ config/         # All configuration setups (e.g., dotenv)
β”œβ”€β”€ controllers/    # Receives HTTP data, handles request/response flow.
β”œβ”€β”€ middlewares/    # Interceptors for auth.
β”œβ”€β”€ models/         # Mongoose models.
β”œβ”€β”€ routes/         # API routing layer
β”œβ”€β”€ utils/          # Helper functions.
└── index.js        # Entry point

Folder Breakdown

  • config/
    Contains setup for environment variables, logging, and other configuration needs.
    Example: server-config.js for dotenv setup, Winston logger setup.

  • routes/
    Handles all route declarations and connects them to controllers and middleware.

  • middlewares/
    Custom middlewares like authenticators, validators, etc., that run before the controller.

  • controllers/
    The last middleware before the business logic. Handles request data and response formatting.

  • utils/
    Utility functions, constants, and custom error classes.


πŸ› οΈ Getting Started

πŸ“¦ Install Dependencies

npm install

βš™οΈ Environment Variables

Create a .env file in the root directory and add the following:

PORT=3000
MONGO_URI=<your-mongodb-connection-string>
JWT_SECRET=<your-jwt-secret>

πŸš€ Running the Server

Development Mode

npm run dev

This uses nodemon for hot reloading.


πŸ“‘ Base API URL

BASE_URL = http://localhost:3000/api/v1

πŸ” Auth Routes

βœ… Register a New User

Endpoint: POST /api/v1/auth/register

Request Body

{
  "email": "test@example.com",
  "password": "yourPassword"
}

Response

{
  "success": true,
  "message": "User created successfully",
  "user": {
    "email": "test@example.com"
  },
  "token": "<jwt_token>"
}

βœ… Login a User

Endpoint: POST /api/v1/auth/login

Request Body

{
  "email": "test@example.com",
  "password": "yourPassword"
}

Response

{
  "success": true,
  "message": "Login successful",
  "user": {
    "email": "test@example.com"
  },
  "token": "<jwt_token>"
}

πŸ“‹ Task Routes

All task routes require a valid JWT token in the Authorization header.

Header:

authorization: Bearer <jwt_token>

πŸ”¨ Create Task

POST /api/v1/task/

Body:

{
  "title": "Sample Task",
  "description": "Task description",
  "status":"Anyone:- ['pending', 'in-progress', 'completed']," 
}

πŸ“₯ Get All Tasks

GET /api/v1/task/

πŸ“ Update Task

PUT /api/v1/task/:id

Body:

{
  "title": "Updated Title"
}w

❌ Delete Task

DELETE /api/v1/task/:id


πŸ“„ API Testing Tools

Use Postman to test the API endpoints.


πŸ“„ Postman Collection Link

Use this - ( https://.postman.co/workspace/My-Workspace~abe6bad2-4e2e-488b-8896-ca2a0ee13ab1/collection/33665598-1ada8d7e-447e-4960-87f0-4eb6ca47599e?action=share&creator=33665598 )


πŸ“„ Deployment details

Deployed on Render.com, free tier instance.


πŸ“„ Deployment Link :- (https://cactro-backend-crud.onrender.com)


πŸ“¬ Contributions

Feel free to open issues or submit pull requests if you find bugs or want to improve the project.

About

API Development and Deployment for a Task Management Backend

https://cactro-backend-crud.onrender.com


Languages

Language:JavaScript 100.0%