A simple Node.js application with dockerized MongoDB, perfect for client demonstrations. This application provides a complete CRUD API for managing products with a beautiful web interface.
- RESTful API with full CRUD operations
- Dockerized MongoDB for easy setup and portability
- Modern Web Interface for interactive demonstrations
- Health Check Endpoints for monitoring
- Sample Data pre-loaded for immediate demo
- Error Handling and validation
- Graceful Shutdown handling
- Docker and Docker Compose
- Node.js (v16 or higher) with N|Solid runtime
- npm (comes with Node.js)
- N|Solid SaaS Token (required for monitoring)
β
Windows (PowerShell, Command Prompt)
β
macOS (Intel & Apple Silicon)
β
Linux (All major distributions)
π Detailed platform instructions: See PLATFORM_SUPPORT.md
# Navigate to project directory
cd mongoInstr
# Start both MongoDB and Node.js app in containers
npm run docker:up-build
# Or manually with docker-compose
docker-compose up -d --build
This will:
- Build and start the Node.js application container
- Start MongoDB container with sample data
- Set up networking between containers
- Expose the app on port 3000
# Navigate to project directory
cd mongoInstr
# Install dependencies
npm install
# Start only MongoDB with Docker
npm run docker:mongo-only
# Start the Node.js application locally
npm start
The application will be available at:
- Web Interface: http://localhost:3000
- API Documentation: http://localhost:3000/api
- Health Check: http://localhost:3000/api/health
Method | Endpoint | Description |
---|---|---|
GET | /api/products |
Get all products |
GET | /api/products/:id |
Get product by ID |
POST | /api/products |
Create new product |
PUT | /api/products/:id |
Update product |
DELETE | /api/products/:id |
Delete product |
Method | Endpoint | Description |
---|---|---|
GET | /api/health |
System health check |
GET | /api |
API documentation |
{
"name": "Laptop",
"price": 999.99,
"category": "Electronics",
"inStock": true
}
- Open http://localhost:3000
- View existing products
- Add a new product using the form
- Delete a product
- Check system health
# Get all products
curl http://localhost:3000/api/products
# Create a new product
curl -X POST http://localhost:3000/api/products \
-H "Content-Type: application/json" \
-d '{"name":"New Product","price":49.99,"category":"Demo","inStock":true}'
# Health check
curl http://localhost:3000/api/health
- Stop MongoDB:
npm run docker:down
- Try to access the app - see error handling
- Restart MongoDB:
npm run docker:up
- Refresh the app - see automatic reconnection
# Build and start both services
npm run docker:up-build
# or
docker-compose up -d --build
# Start services (without rebuilding)
npm run docker:up
# or
docker-compose up -d
# Stop all services
npm run docker:down
# or
docker-compose down
# View logs for all services
npm run docker:logs
# or
docker-compose logs -f
# View logs for specific service
docker-compose logs -f app
docker-compose logs -f mongodb
# Start only MongoDB
npm run docker:mongo-only
# or
docker-compose up -d mongodb
# Access MongoDB shell
docker exec -it mongo-demo mongosh -u demo_user -p demo_password --authenticationDatabase demo_db
# Build the Node.js application image
npm run docker:build
# or
docker-compose build
# Rebuild and restart services
docker-compose up -d --build
mongoInstr/
βββ public/
β βββ index.html # Web interface
βββ routes/
β βββ products.js # Product API routes
βββ .env # Environment variables
βββ database.js # MongoDB connection logic
βββ docker-compose.yml # Docker configuration
βββ init-mongo.js # MongoDB initialization script
βββ package.json # Node.js dependencies
βββ server.js # Main application server
βββ README.md # This file
MONGODB_URI=mongodb://demo_user:demo_password@localhost:27017/demo_db
MONGODB_HOST=localhost
MONGODB_PORT=27017
MONGODB_DATABASE=demo_db
MONGODB_USERNAME=demo_user
MONGODB_PASSWORD=demo_password
PORT=3000
NODE_ENV=development
- Database:
demo_db
- Collection:
products
- Username:
demo_user
- Password:
demo_password
- Port:
27017
-
Check if Docker is running:
docker ps
-
Check MongoDB container status:
docker-compose ps
-
View MongoDB logs:
docker-compose logs mongodb
-
Restart MongoDB:
npm run docker:down npm run docker:up
-
Check if port 3000 is available:
netstat -an | findstr :3000
-
Install dependencies:
npm install
-
Check environment variables:
- Ensure
.env
file exists - Verify MongoDB connection string
- Ensure
- Update the product schema in
routes/products.js
- Modify the web interface in
public/index.html
- Update the initialization script in
init-mongo.js
- Update
docker-compose.yml
for different MongoDB settings - Modify
.env
file with new connection details - Update
init-mongo.js
for different sample data
This project is licensed under the MIT License - see the package.json file for details.
This is a demo application. Feel free to fork and modify for your own demonstrations!
Perfect for client demos showcasing:
- Modern web development practices
- Docker containerization
- RESTful API design
- MongoDB integration
- Error handling and validation
- Responsive web interfaces