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
-
config/
Contains setup for environment variables, logging, and other configuration needs.
Example:server-config.jsfor 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.
npm installCreate a .env file in the root directory and add the following:
PORT=3000
MONGO_URI=<your-mongodb-connection-string>
JWT_SECRET=<your-jwt-secret>npm run devThis uses
nodemonfor hot reloading.
BASE_URL = http://localhost:3000/api/v1
Endpoint: POST /api/v1/auth/register
{
"email": "test@example.com",
"password": "yourPassword"
}{
"success": true,
"message": "User created successfully",
"user": {
"email": "test@example.com"
},
"token": "<jwt_token>"
}Endpoint: POST /api/v1/auth/login
{
"email": "test@example.com",
"password": "yourPassword"
}{
"success": true,
"message": "Login successful",
"user": {
"email": "test@example.com"
},
"token": "<jwt_token>"
}All task routes require a valid JWT token in the Authorization header.
Header:
authorization: Bearer <jwt_token>
POST /api/v1/task/
{
"title": "Sample Task",
"description": "Task description",
"status":"Anyone:- ['pending', 'in-progress', 'completed'],"
}GET /api/v1/task/
PUT /api/v1/task/:id
{
"title": "Updated Title"
}wDELETE /api/v1/task/:id
Use Postman to test the API endpoints.
Use this - ( https://.postman.co/workspace/My-Workspace~abe6bad2-4e2e-488b-8896-ca2a0ee13ab1/collection/33665598-1ada8d7e-447e-4960-87f0-4eb6ca47599e?action=share&creator=33665598 )
Deployed on Render.com, free tier instance.
π Deployment Link :- (https://cactro-backend-crud.onrender.com)
Feel free to open issues or submit pull requests if you find bugs or want to improve the project.