Skip to content

farizmuhammad/test-angular-app

Repository files navigation

Test App - Angular + Node.js + MongoDB

Full-stack web application menggunakan Angular 19, Node.js/Express, dan MongoDB.

Fitur

  • βœ… Angular 19 frontend dengan standalone components
  • βœ… Node.js/Express REST API backend
  • βœ… MongoDB database
  • βœ… Environment configuration untuk development & production
  • βœ… CORS enabled
  • βœ… Ready untuk production deployment

Quick Start - Development

Prerequisites

  • Node.js 20.x atau lebih baru
  • npm
  • MongoDB (local atau remote)

Installation

  1. Clone repository

    git clone <repository-url>
    cd test-app
  2. Setup Backend

    cd server
    npm install
    cp .env.example .env
    # Edit .env sesuai konfigurasi MongoDB Anda
  3. Setup Frontend

    cd ..
    npm install
  4. Start MongoDB

    # Pastikan MongoDB sudah running
    sudo systemctl start mongod
  5. Seed Sample Data

    cd server
    node seed-data.js
  6. Run Backend

    npm start
    # Backend running at http://localhost:3000
  7. Run Frontend (terminal baru)

    cd ..
    npm start
    # Frontend running at http://localhost:4200
  8. Open Browser

    http://localhost:4200
    

Documentation

Development Setup

πŸ“– SETUP.md - Panduan lengkap setup development environment

Production Deployment

πŸ“– DEPLOYMENT.md - Dokumentasi lengkap deployment ke VPS πŸ“– QUICKSTART-DEPLOY.md - Quick start deployment guide


Project Structure

test-app/
β”œβ”€β”€ src/                          # Angular frontend source
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   └── titles/          # Titles page component
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── title.service.ts # API service
β”‚   β”‚   β”œβ”€β”€ app.component.*      # Root component
β”‚   β”‚   β”œβ”€β”€ app.config.ts        # App configuration
β”‚   β”‚   └── app.routes.ts        # Routing configuration
β”‚   └── environments/            # Environment configurations
β”‚       β”œβ”€β”€ environment.ts       # Development config
β”‚       β”œβ”€β”€ environment.prod.ts  # Production config
β”‚       └── environment.example.ts # Template
β”‚
β”œβ”€β”€ server/                      # Node.js backend
β”‚   β”œβ”€β”€ server.js               # Express server
β”‚   β”œβ”€β”€ seed-data.js            # Sample data script
β”‚   β”œβ”€β”€ test-connection.js      # MongoDB test script
β”‚   β”œβ”€β”€ package.json            # Backend dependencies
β”‚   β”œβ”€β”€ .env                    # Environment variables (not committed)
β”‚   └── .env.example            # Environment template
β”‚
β”œβ”€β”€ scripts/                    # Deployment & maintenance scripts
β”‚   β”œβ”€β”€ setup-vps.sh           # VPS initial setup
β”‚   β”œβ”€β”€ backup-mongodb.sh      # MongoDB backup script
β”‚   └── restore-mongodb.sh     # MongoDB restore script
β”‚
β”œβ”€β”€ deploy.sh                  # Auto deployment script
β”œβ”€β”€ ecosystem.config.js        # PM2 configuration
β”œβ”€β”€ nginx.conf.example         # Nginx configuration template
β”‚
β”œβ”€β”€ SETUP.md                   # Development setup guide
β”œβ”€β”€ DEPLOYMENT.md              # Production deployment guide
β”œβ”€β”€ QUICKSTART-DEPLOY.md       # Quick deployment guide
└── README.md                  # This file

Environment Variables

Backend (server/.env)

PORT=3000
MONGODB_URI=mongodb://localhost:27017
DB_NAME=testdb
COLLECTION_NAME=titles
NODE_ENV=development

Frontend (src/environments/environment.ts)

export const environment = {
  production: false,
  apiUrl: 'http://localhost:3000/api'
};

API Endpoints

Base URL: http://localhost:3000/api

Method Endpoint Description
GET /titles Get all titles
POST /titles Create new title

Example Request

# Get all titles
curl http://localhost:3000/api/titles

# Create new title
curl -X POST http://localhost:3000/api/titles \
  -H "Content-Type: application/json" \
  -d '{"title":"New Title"}'

Scripts

Development

# Run backend
cd server && npm start

# Run frontend
npm start

# Build for production
npm run build -- --configuration production

Testing & Utilities

# Test MongoDB connection
cd server && node test-connection.js

# Add sample data
cd server && node seed-data.js

Deployment (VPS)

# Initial VPS setup
bash scripts/setup-vps.sh

# Deploy/Update application
bash deploy.sh

# Backup MongoDB
bash scripts/backup-mongodb.sh

# Restore MongoDB
bash scripts/restore-mongodb.sh backup_file.tar.gz

Production Deployment

Quick Deploy to VPS

  1. Setup VPS (one time)

    bash scripts/setup-vps.sh
  2. Configure environment

    # Backend
    cd server
    cp .env.example .env
    nano .env  # Edit with production values
    
    # Frontend
    nano src/environments/environment.prod.ts  # Edit apiUrl
  3. Deploy

    bash deploy.sh

πŸ“– See QUICKSTART-DEPLOY.md for detailed instructions.


Technologies

Frontend

  • Angular 19 - Web framework
  • TypeScript - Programming language
  • RxJS - Reactive programming

Backend

  • Node.js - Runtime environment
  • Express - Web framework
  • MongoDB - NoSQL database
  • dotenv - Environment configuration

DevOps & Deployment

  • PM2 - Process manager
  • Nginx - Web server & reverse proxy
  • Let's Encrypt - SSL/TLS certificates

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open Pull Request

Troubleshooting

MongoDB Connection Error

# Check MongoDB status
sudo systemctl status mongod

# Test connection
cd server && node test-connection.js

Backend API Not Running

# Development
cd server && npm start

# Production
pm2 status
pm2 logs test-app-api

Frontend Not Loading

# Clear cache and rebuild
rm -rf node_modules .angular dist
npm install
npm start

CORS Issues

Make sure backend CORS is configured in server/server.js:

app.use(cors());

Support & Documentation


License

This project is open source and available under the MIT License.


Author

Marore Bestari Indonesia


Changelog

v1.0.0 (2025-01-21)

  • Initial release
  • Angular 19 frontend
  • Node.js/Express backend
  • MongoDB integration
  • Environment configuration
  • Production deployment ready

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published