Skip to content

YousseifNady/dockerized-express-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dockerized Express API

A simple RESTful API built with Node.js, Express, and MongoDB, containerized using Docker and orchestrated with Docker Compose.

The project demonstrates how to package an application and its dependencies into isolated containers, providing a consistent development environment and simplifying deployment workflows.


📖 Overview

The application consists of two services:

  • Express API Container – Runs the Node.js application.
  • MongoDB Container – Provides persistent data storage.

Both services communicate through an isolated Docker network and are managed using Docker Compose.


🏗️ Architecture

Client
   │
   ▼
┌─────────────────┐
│  Express API    │
│   (Container)   │
└────────┬────────┘
         │
         │ Docker Network
         │
┌────────▼────────┐
│    MongoDB      │
│   (Container)   │
└─────────────────┘

✨ Features

  • Dockerized Node.js and Express application
  • MongoDB running in a separate container
  • Multi-container orchestration with Docker Compose
  • Environment-based configuration using .env
  • Persistent MongoDB storage using Docker volumes
  • Container-to-container communication through Docker networking
  • Development-friendly setup with bind mounts and automatic reloads
  • JWT-based authentication

🐳 Why Docker?

Docker provides several advantages:

  • Consistency – The application runs the same way across different environments.
  • Isolation – Dependencies are encapsulated inside containers.
  • Portability – The entire stack can run on any machine with Docker installed.
  • Reproducibility – Team members can start the project with a single command.
  • Scalability – Services can be extended and orchestrated more easily.

📋 Prerequisites

Before running the application, make sure you have:

  • Docker
  • Docker Compose

🚀 Getting Started

Clone the Repository

git clone https://github.com/YousseifNady/dockerized-express-api.git
cd dockerized-express-api

Configure Environment Variables

Create a .env file in the project root:

PORT=3000

# MongoDB
DB_USER=admin
DB_PASSWORD=admin123
DB_DATABASE=appdb
DB_HOST=mongo
DB_PORT=27017

DB_URL=mongodb://admin:admin123@mongo:27017/appdb?authSource=admin

JWT_SECRET_KEY=12345test

Note: The application will not start correctly without these environment variables. Docker Compose uses them to configure both the Express application and the MongoDB container.


Start the Application

docker compose up --build

The API will be available at:

http://localhost:3000

MongoDB will be available at:

mongodb://localhost:27017

Stop the Application

docker compose down

Remove containers and volumes:

docker compose down -v

📚 API Documentation

API endpoints, request payloads, and response examples are documented in:

API.md

This documentation includes:

  • Authentication endpoints
  • User management APIs
  • Request and response examples
  • Required headers and payloads

📂 Project Structure

.
├── app/
├── index.js
├── Dockerfile
├── docker-compose.yml
├── package.json
├── API.md
├── .env
└── README.md

🎯 Learning Objectives

This project demonstrates practical usage of:

  • Docker Images
  • Docker Containers
  • Docker Networks
  • Docker Volumes
  • Bind Mounts
  • Environment Variables
  • Docker Compose
  • Multi-service applications
  • Containerized development workflows
  • JWT Authentication

🔒 Security Note

The credentials and secrets provided in the example .env file are intended for local development only. Use secure passwords and secrets in production environments.


📄 License

This project is intended for learning purposes and demonstrates how to containerize a Node.js and MongoDB application using Docker and Docker Compose.

About

Containerized Node.js and MongoDB application demonstrating Docker, Docker Compose, networking, volumes, and environment-based configuration.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors