Skip to content

A secure task management API built with Node.js, Express, and MongoDB, offering authenticated users complete control over their tasks.

License

Notifications You must be signed in to change notification settings

saarv3sh7/Task-Manager-API

Repository files navigation

Task Manager API (Backend)

This is a simple Task Manager API built using Node.js, Express.js, and MongoDB. It supports user registration and authentication using JWT and allows users to perform full CRUD operations on tasks. Each task is associated with a specific authenticated user.

Features

  • User Registration and Login (JWT Authentication)
  • Create, Read, Update, and Delete (CRUD) tasks
  • Tasks are user-specific
  • RESTful API architecture
  • MongoDB for data storage

Tech Stack

  • Node.js
  • Express.js
  • MongoDB
  • JSON Web Token (JWT)
  • Bcrypt.js (for password hashing)
  • Postman (for testing)

Folder Structure

Task_Manager_API/
├── controllers/
│ ├── taskController.js
│ └── userController.js
├── middleware/
│ └── auth.js
├── models/
│ ├── Task.js
│ └── User.js
├── routes/
│ ├── taskRoutes.js
│ └── userRoutes.js
├── .env
├── app.js
├── server.js

Setup Instructions (for Mac)

  1. Clone the repository
git clone https://github.com/saarv3sh7/Task-Manager-API.git
cd Task_Manager_API
  1. Install dependencies
npm install
  1. Create .env file
PORT=5000
MONGO_URI=mongodb://127.0.0.1:27017/task-manager-api
JWT_SECRET=your_jwt_secret
  1. Start MongoDB locally
mongod --dbpath <MongoDB-db-Folder>
  1. Run the server
npm start

Server runs on: http://localhost:5000


API Endpoints

User Routes

Method Endpoint Description
POST /api/users/register Register new user
POST /api/users/login Login and get JWT

Task Routes (Require Bearer Token)

Method Endpoint Description
GET /api/tasks Get all user tasks
POST /api/tasks Create new task
PUT /api/tasks/:id Update task by ID
DELETE /api/tasks/:id Delete task by ID

Postman API Testing Guide

  1. Register
  • Method: POST
  • URL: http://localhost:5000/api/users/register
  • Body (raw JSON):
    {
      "name": "Sarvesh",
      "email": "test@example.com",
      "password": "123456"
    }
  1. Login
  • Method: POST
  • URL: http://localhost:5000/api/users/login
  • Body (raw JSON):
    {
      "email": "test@example.com",
      "password": "123456"
    }
  • Copy the token from response for the next requests
  1. Get All Tasks
  • Method: GET
  • URL: http://localhost:5000/api/tasks
  • Header:
    Authorization: Bearer <token>
    
  1. Create Task
  • Method: POST
  • URL: http://localhost:5000/api/tasks
  • Header:
    Authorization: Bearer <token>
    
  • Body:
    {
      "title": "Complete Assignment",
      "description": "Finish backend API assignment"
    }
  1. Update Task
  • Method: PUT
  • URL: http://localhost:5000/api/tasks/<task_id>
  • Header:
    Authorization: Bearer <token>
    
  • Body:
    {
      "completed": true
    }
  1. Delete Task
  • Method: DELETE
  • URL: http://localhost:5000/api/tasks/<task_id>
  • Header:
    Authorization: Bearer <token>
    

About

A secure task management API built with Node.js, Express, and MongoDB, offering authenticated users complete control over their tasks.

Topics

Resources

License

Stars

Watchers

Forks