Skip to content

HephtronCode/Task-Manager-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

A simple RESTful API for managing tasks, built with Node.js, Express, and MongoDB (using Mongoose). This project is designed for learning purposes and demonstrates how to create, read, update, and delete (CRUD) tasks in a MongoDB database.

Features

  • Create Tasks: Add new tasks with a title and description.
  • Read Tasks: Retrieve all tasks or a specific task by its ID.
  • Update Tasks: Modify existing tasks by ID.
  • Delete Tasks: Remove tasks from the database by ID.
  • Data Validation: Ensures required fields are present and properly formatted.
  • Error Handling: Graceful error responses for invalid requests or server issues.

Technologies Used

Getting Started

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/task-manager.git
    cd task-manager
  2. Install dependencies:

    npm install
  3. Start MongoDB:
    Make sure your MongoDB server is running. By default, the app connects to mongodb://localhost:27017/taskdb.

  4. Run the server:

    node server.js

    The server will start on port 3000.

API Endpoints

Create a Task

  • POST /tasks
  • Body Example:
    {
      "title": "Learn Node.js",
      "description": "Study Express and Mongoose basics"
    }
  • Response: Returns the created task object.

Get All Tasks

  • GET /tasks
  • Response: Returns an array of all tasks.

Get a Task by ID

  • GET /tasks/:id
  • Response: Returns the task object with the specified ID.

Update a Task

  • PUT /tasks/:id
  • Body Example:
    {
      "completed": true
    }
  • Response: Returns the updated task object.

Delete a Task

  • DELETE /tasks/:id
  • Response: Returns a success message if the task is deleted.

Project Structure

task-manager/
├── server.js       # Entry point, sets up Express and MongoDB connection
├── task.js         # Mongoose schema/model for tasks
├── routes.js       # Express routes for task CRUD operations
├── package.json    # Project metadata and dependencies
└── README.md       # Project documentation

Learning Highlights

  • How to structure a Node.js REST API project
  • Using Mongoose for schema definition and data validation
  • Implementing CRUD operations with Express routes
  • Handling errors and sending appropriate HTTP responses

License

This project is for educational purposes only.


Happy coding! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published