A tour booking application built with Node.js, Express, and MongoDB.
- User authentication and authorization
- Tour booking with payment processing
- User reviews and ratings
- Tour search and filtering
- Email notifications
- Backend: Node.js with Express
- Database: MongoDB
- Template Engine: Pug
- CSS: Custom CSS
- Authentication: JWT (JSON Web Tokens)
- Containerization: Docker and Docker Compose
- Payment Processing: Stripe API
For local development without Docker:
- Create a
.envfile in the root directory with the following variables:
NODE_ENV=development
PORT=3000
MONGODB_LOCAL_URL=localhost:27017/natours
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90
EMAIL_USERNAME=your_email_username
EMAIL_PASSWORD=your_email_password
EMAIL_HOST=your_email_host
EMAIL_PORT=your_email_port
EMAIL_FROM=youremail@example.com
GMAIL_USERNAME=your_gmail_username@gmail.com
GMAIL_PASSWORD=your_gmail_app_password
STRIPE_SECRET_KEY=your_stripe_secret_key
npm installnpm run devThis application is fully containerized for production environment.
- Docker and Docker Compose installed on your system
- Create a
docker.envfile in the root directory with the following variables:
NODE_ENV=production
PORT=3000
MONGODB_LOCAL_URL=mongodb://mongo:27017/natours
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=90d
JWT_COOKIE_EXPIRES_IN=90
EMAIL_USERNAME=your_email_username
EMAIL_PASSWORD=your_email_password
EMAIL_HOST=your_email_host
EMAIL_PORT=your_email_port
EMAIL_FROM=youremail@example.com
GMAIL_USERNAME=your_gmail_username@gmail.com
GMAIL_PASSWORD=your_gmail_app_password
STRIPE_SECRET_KEY=your_stripe_secret_key
Run the application in production mode:
docker compose up -dThis will start both the Node.js application and MongoDB database in detached mode.
To import sample data into MongoDB:
docker exec -it natours-app node ./dev-data/data/import-dev-data.js --importTo delete all data:
docker exec -it natours-app node ./dev-data/data/import-dev-data.js --deleteThe Docker image for this application is available on DockerHub. You can pull it directly:
docker pull husseinsaad1/natours:latestThe application is orchestrated using Docker Compose and consists of:
-
Node.js Application (app):
- Uses pre-built image
husseinsaad1/natours:latest - Connected to MongoDB
- Exposed on port 3000
- Uses pre-built image
-
MongoDB Database (mongo):
- Uses official MongoDB 5.0 image
- Persistent data storage via Docker volumes
- Exposed on port 27018 (mapped from 27017)
-
Network Configuration:
- Dedicated bridge network (
natours-network) between app and MongoDB services - Isolated communication between the application and database
- Enhanced security by isolating database from external networks
- Dedicated bridge network (
- Start the services:
docker-compose up -d - Stop the services:
docker-compose down - View logs:
docker-compose logs -f app
The Docker setup follows security best practices:
- Non-root user for Node.js application
- No exposed database credentials
- Production dependencies only in final image
- Multi-stage build to minimize image size
- Lightweight Alpine base image