MEAN Stack
MongoDB, Express, Angular, Node.js full-stack setup.
Overview
The MEAN stack combines MongoDB, Express.js, Angular, and Node.js into a JavaScript-first full-stack development platform. MongoDB serves as the document-oriented NoSQL database, storing data in flexible JSON-like documents that align naturally with JavaScript objects. Express.js provides the web application framework running on Node.js for the backend API, while Angular handles the frontend single-page application with TypeScript support and component-based architecture.
This Docker configuration creates a three-tier architecture where Angular serves the client-side application on port 4200, Express.js handles API requests on port 3000, and MongoDB manages data persistence on the internal network. The stack leverages JavaScript throughout the entire application lifecycle, from database queries using MongoDB's native JavaScript drivers to frontend rendering with Angular's TypeScript-compiled components. The containerized approach isolates each service while maintaining communication through a dedicated Docker network.
Developers building modern web applications, startups requiring rapid prototyping capabilities, and teams seeking a unified JavaScript development experience will find this stack particularly valuable. The MEAN architecture excels in scenarios requiring real-time data updates, content management systems, and applications with evolving schemas where MongoDB's flexibility shines alongside Angular's dynamic frontend capabilities.
Key Features
- Document-based data storage with MongoDB's flexible JSON-like schema design
- Real-time data binding between Angular components and Express.js API endpoints
- MongoDB aggregation framework for complex data analytics and reporting
- Angular's component-based architecture with dependency injection and routing
- Express.js middleware ecosystem for authentication, logging, and request processing
- Node.js event-driven architecture enabling high-concurrent connection handling
- MongoDB change streams for real-time application updates and notifications
- Angular CLI integration for rapid component generation and build optimization
Common Use Cases
- 1Content management systems requiring flexible document schemas and rich user interfaces
- 2Social media platforms with real-time feeds, user interactions, and dynamic content
- 3E-commerce applications managing product catalogs, user profiles, and order processing
- 4Project management tools with collaborative features and document storage
- 5Blog platforms and publishing systems with rich text editing and media management
- 6Dashboard applications displaying real-time analytics and business intelligence
- 7Learning management systems with course content, user progress tracking, and assessments
Prerequisites
- Docker and Docker Compose installed with minimum 4GB RAM available for containers
- Angular CLI installed globally for frontend development and build processes
- Node.js and npm knowledge for Express.js backend development and package management
- Ports 3000, 4200, and 27017 available on the host system
- Basic understanding of TypeScript for Angular component development
- MongoDB query syntax familiarity for database operations and aggregation pipelines
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 frontend: 3 build: 4 context: ./frontend5 dockerfile: Dockerfile6 container_name: angular-frontend7 ports: 8 - "4200:4200"9 networks: 10 - mean1112 backend: 13 build: 14 context: ./backend15 dockerfile: Dockerfile16 container_name: express-backend17 environment: 18 MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}19 ports: 20 - "3000:3000"21 depends_on: 22 - mongodb23 networks: 24 - mean2526 mongodb: 27 image: mongo:728 container_name: mongodb29 volumes: 30 - mongodb_data:/data/db31 networks: 32 - mean3334volumes: 35 mongodb_data: 3637networks: 38 mean: 39 driver: bridge.env Template
.env
1DB_NAME=meanappUsage Notes
- 1Docs: https://angular.io/guide/setup-local
- 2Create frontend/ with ng new (Angular CLI)
- 3Create backend/ with Express.js API
- 4Frontend at http://localhost:4200, API at http://localhost:3000
- 5MongoDB connection: mongodb://mongodb:27017/dbname
- 6Use HttpClient module for API requests
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
frontend
frontend:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: angular-frontend
ports:
- "4200:4200"
networks:
- mean
backend
backend:
build:
context: ./backend
dockerfile: Dockerfile
container_name: express-backend
environment:
MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}
ports:
- "3000:3000"
depends_on:
- mongodb
networks:
- mean
mongodb
mongodb:
image: mongo:7
container_name: mongodb
volumes:
- mongodb_data:/data/db
networks:
- mean
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 frontend:5 build:6 context: ./frontend7 dockerfile: Dockerfile8 container_name: angular-frontend9 ports:10 - "4200:4200"11 networks:12 - mean1314 backend:15 build:16 context: ./backend17 dockerfile: Dockerfile18 container_name: express-backend19 environment:20 MONGODB_URI: mongodb://mongodb:27017/${DB_NAME}21 ports:22 - "3000:3000"23 depends_on:24 - mongodb25 networks:26 - mean2728 mongodb:29 image: mongo:730 container_name: mongodb31 volumes:32 - mongodb_data:/data/db33 networks:34 - mean3536volumes:37 mongodb_data:3839networks:40 mean:41 driver: bridge42EOF4344# 2. Create the .env file45cat > .env << 'EOF'46DB_NAME=meanapp47EOF4849# 3. Start the services50docker compose up -d5152# 4. View logs53docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/mean-stack/run | bashTroubleshooting
- Angular build fails with memory errors: Increase Docker container memory limits or add NODE_OPTIONS=--max-old-space-size=4096 to frontend environment
- MongoDB connection refused from Express.js: Ensure backend service depends_on mongodb and uses hostname 'mongodb' instead of 'localhost' in connection string
- CORS errors when Angular calls Express API: Configure Express.js with cors middleware allowing origin http://localhost:4200
- Frontend container exits immediately: Verify Angular CLI is properly installed and package.json contains valid start script for development server
- MongoDB data loss after container restart: Ensure mongodb_data volume is properly mounted to /data/db and has sufficient disk space
- Express.js crashes with module not found: Check that backend Dockerfile includes npm install step and all dependencies are listed in package.json
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download