Skip to content

A simple Node.js RESTful API designed for basic task management. Includes features such as user authentication, multi-tenancy support, basic CRUD operations , and a suite of tests

License

Notifications You must be signed in to change notification settings

munuhee/task-manager-api

Repository files navigation

Task Management API

Overview

The Node.js Task Management API is a RESTful API designed to handle task management with features like user authentication, multi-tenancy, and comprehensive data operations. Built with Node.js, Express, and MongoDB, this project provides a scalable and secure solution for managing tasks. It is containerized with Docker for consistent deployment across environments.

Features

  • User Authentication: Secure registration and login with JWT-based authentication.
  • Task Management: Full CRUD (Create, Read, Update, Delete) operations for tasks.
  • Multi-Tenancy: Support for multiple tenants with isolated data.
  • Testing: Unit and integration tests ensure code reliability and correctness.
  • Docker Integration: Simplifies deployment with Docker and Docker Compose.
  • Logging and Validation: Robust logging and data validation for improved reliability.

Tech Stack

  • Node.js: JavaScript runtime for server-side development.
  • Express: Web framework for building the API.
  • MongoDB: NoSQL database for flexible data storage.
  • Mongoose: ODM library for MongoDB.
  • JWT: JSON Web Token for user authentication.
  • Chai & Mocha: Testing frameworks for unit and integration tests.
  • Docker: Containerization for consistent development and deployment.

Prerequisites

Ensure the following are installed before setting up the project:

  • Node.js: Version 18.x or higher.
  • MongoDB: Either locally installed or running via Docker.
  • Docker: (Optional) For containerized development and deployment.

Installation

Clone the Repository

Clone the repository to your local machine:

git clone https://github.com/munuhee/task-manager-api
cd your-repository

Install Dependencies

Install the project dependencies using npm:

npm install

Environment Configuration

Create a .env file in the root directory with the following content:

NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/myDatabase
JWT_SECRET=your_jwt_secret
PORT=3000
  • NODE_ENV: Set to development for local development or production for production environments.
  • MONGO_URI: Connection string for MongoDB.
  • JWT_SECRET: Secret key for signing JWT tokens.
  • PORT: Port for the application server (default is 3000).

Running the Application

Start the Server

To start the server, use:

npm start

The API will be accessible at http://localhost:3000.

Running with Docker

Use Docker to containerize the application:

Build Docker Images

docker-compose build

Start Containers

docker-compose up

The application will be available at http://localhost:3000 and MongoDB will be accessible at mongodb://localhost:27017.

Stop Containers

To stop and remove the containers:

docker-compose down

API Endpoints

User Authentication

  • Register User: POST /api/auth/register

    • Request Body:
      {
        "username": "string",
        "password": "string",
        "email": "string"
      }
    • Response:
      {
        "message": "User registered successfully"
      }
  • Login User: POST /api/auth/login

    • Request Body:
      {
        "username": "string",
        "password": "string"
      }
    • Response:
      {
        "token": "string"
      }

Task Management

  • Create Task: POST /api/tasks

    • Request Body:
      {
        "title": "string",
        "description": "string",
        "dueDate": "ISODate",
        "priority": "string"
      }
    • Response:
      {
        "task": {
          "id": "string",
          "title": "string",
          ...
        }
      }
  • Get Tasks: GET /api/tasks

    • Response:
      [
        {
          "id": "string",
          "title": "string",
          ...
        }
      ]
  • Update Task: PUT /api/tasks/:taskId

    • Request Body:
      {
        "title": "string",
        "description": "string",
        "dueDate": "ISODate",
        "priority": "string"
      }
    • Response:
      {
        "task": {
          "id": "string",
          "title": "string",
          ...
        }
      }
  • Delete Task: DELETE /api/tasks/:taskId

    • Response:
      {
        "message": "Task deleted successfully"
      }

Testing

Unit Tests

Run unit tests to validate individual components:

npm test

Tests

Run tests:

npm test

Configuration

Ports

  • Application Port: The API runs on port 3000 by default.
  • MongoDB Port: MongoDB runs on port 27017.

Logging

  • Development Logging: Detailed logs are enabled.
  • Production Logging: Reduced verbosity to optimize performance.

Error Handling

  • Development: Detailed error messages and stack traces are enabled.
  • Production: Generic error messages with detailed logs stored.

About

A simple Node.js RESTful API designed for basic task management. Includes features such as user authentication, multi-tenancy support, basic CRUD operations , and a suite of tests

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published