Skip to content

Avi-reck/decodelabs_task_2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StudyMate Backend API

StudyMate Backend API is a RESTful backend project built using Node.js and Express.js. It is developed as part of DecodeLabs Full Stack Development Project 2, focused on backend API development, server-side logic, input validation, and REST API concepts.

This backend provides APIs to manage student study tasks such as adding tasks, fetching tasks, updating task details, marking tasks as completed, deleting tasks, and filtering tasks based on subject or completion status.

Project Overview

The main objective of this project is to build a simple and structured backend API that can handle application logic and manage data flow between a frontend application and the server.

The project uses JSON file-based storage, so task data is saved inside a local tasks.json file without using a database.

Features

  • Create a new study task
  • Get all study tasks
  • Get a single task by ID
  • Update task details
  • Mark task as completed
  • Delete a task
  • Filter tasks by subject
  • Filter tasks by completed status
  • Basic input validation
  • Proper HTTP status codes
  • JSON file-based data storage
  • Clean folder structure using routes, controllers, and middleware
  • CORS enabled for frontend connection
  • Error handling for invalid routes and invalid task IDs

Tech Stack

  • Node.js
  • Express.js
  • JavaScript
  • CORS
  • Nodemon
  • JSON

Folder Structure

studymate-backend/
│
├── controllers/
│   └── taskController.js
│
├── data/
│   └── tasks.json
│
├── middleware/
│   └── validateTask.js
│
├── routes/
│   └── taskRoutes.js
│
├── node_modules/
│
├── .gitignore
├── package-lock.json
├── package.json
├── README.md
└── server.js

API Base URL

http://localhost:5000

API Endpoints

Home Route

GET /

Response:

StudyMate Backend API is running...

Get All Tasks

GET /api/tasks

Response Example:

{
  "success": true,
  "message": "Tasks fetched successfully",
  "count": 0,
  "data": []
}

Get Single Task by ID

GET /api/tasks/:id

Example:

GET /api/tasks/1765460000000

Add New Task

POST /api/tasks

Request Body:

{
  "title": "Complete DBMS Assignment",
  "subject": "DBMS",
  "deadline": "2026-06-15",
  "priority": "High"
}

Response Example:

{
  "success": true,
  "message": "Task added successfully",
  "data": {
    "id": 1765460000000,
    "title": "Complete DBMS Assignment",
    "subject": "DBMS",
    "deadline": "2026-06-15",
    "priority": "High",
    "completed": false,
    "createdAt": "2026-06-11T18:00:00.000Z"
  }
}

Update Task

PUT /api/tasks/:id

Example:

PUT /api/tasks/1765460000000

Request Body:

{
  "completed": true
}

You can also update other task fields:

{
  "title": "Complete Operating System Notes",
  "subject": "Operating System",
  "deadline": "2026-06-20",
  "priority": "Medium",
  "completed": false
}

Delete Task

DELETE /api/tasks/:id

Example:

DELETE /api/tasks/1765460000000

Filter Tasks by Subject

GET /api/tasks?subject=DBMS

Filter Tasks by Completed Status

GET /api/tasks?completed=true

or

GET /api/tasks?completed=false

Sample Task Object

{
  "id": 1765460000000,
  "title": "Complete DBMS Assignment",
  "subject": "DBMS",
  "deadline": "2026-06-15",
  "priority": "High",
  "completed": false,
  "createdAt": "2026-06-11T18:00:00.000Z"
}

Validation

The API validates required task fields before creating a new task.

Required fields:

title
subject

If required fields are missing, the API returns:

{
  "success": false,
  "message": "Task title is required"
}

or

{
  "success": false,
  "message": "Task subject is required"
}

How to Run the Project Locally

1. Clone the Repository

git clone https://github.com/Avi-reck/studymate-backend.git

2. Go to Project Folder

cd studymate-backend

3. Install Dependencies

npm install

4. Run the Server

For development mode:

npm run dev

For normal mode:

npm start

Server will start on:

http://localhost:5000

Testing the API

You can test the API using:

  • Thunder Client
  • Postman
  • Browser for GET requests

Recommended testing order:

1. GET /
2. GET /api/tasks
3. POST /api/tasks
4. GET /api/tasks/:id
5. PUT /api/tasks/:id
6. DELETE /api/tasks/:id

Important GitHub Note

Do not upload the node_modules folder to GitHub.

The .gitignore file should contain:

node_modules/
.env

Project Learning Outcomes

Through this project, I learned:

  • How to create a backend server using Express.js
  • How to build RESTful API endpoints
  • How to handle GET, POST, PUT, and DELETE requests
  • How to validate user input using middleware
  • How to organize backend code using routes and controllers
  • How to store and manage data using a JSON file
  • How to return proper HTTP status codes and API responses
  • How frontend and backend communicate through API requests

Author

Aviral Singh B.Tech CSE (AI & ML) Student Frontend & Full Stack Development Enthusiast

GitHub: Avi-reck

About

RESTful Backend API for StudyMate built with Node.js, Express.js, JSON storage, validation, and CRUD operations.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages