Aplikasi CRUD (Create, Read, Update, Delete) sederhana untuk manajemen produk menggunakan React.js sebagai frontend dan Node.js/Express sebagai backend yang terhubung ke AWS RDS MySQL.
- β CRUD Product: Create, Read, Update, Delete produk
- β Search & Filter: Pencarian produk berdasarkan nama/deskripsi dan filter kategori
- β Pagination: Navigasi halaman untuk performa optimal
- β Responsive Design: Tampilan yang responsif di semua device
- β Real-time Updates: Data yang selalu ter-update
- β Form Validation: Validasi input yang komprehensif
- β Error Handling: Penanganan error yang baik
- β AWS RDS Integration: Terhubung langsung ke AWS RDS MySQL
- React.js 19 - UI Library
- Axios - HTTP Client
- CSS3 - Styling dengan modern design
- Node.js - JavaScript Runtime
- Express.js - Web Framework
- MySQL2 - MySQL Driver dengan Promise support
- CORS - Cross-Origin Resource Sharing
- dotenv - Environment Variables
- AWS RDS MySQL - Cloud Database Service
react-product-crud/
βββ backend/
β βββ config/
β β βββ database.js # Konfigurasi database
β βββ controllers/
β β βββ productController.js # Logic bisnis products
β βββ models/
β β βββ Product.js # Model Product
β βββ routes/
β β βββ productRoutes.js # API Routes
β βββ .env # Environment Variables
β βββ package.json
β βββ server.js # Server utama
βββ frontend/
β βββ public/
β β βββ index.html
β βββ src/
β β βββ components/
β β β βββ ProductCard.js # Komponen card produk
β β β βββ ProductCard.css
β β β βββ ProductForm.js # Form add/edit produk
β β β βββ ProductForm.css
β β βββ hooks/
β β β βββ useProducts.js # Custom hooks
β β βββ pages/
β β β βββ Products.js # Halaman utama
β β β βββ Products.css
β β βββ services/
β β β βββ api.js # API service layer
β β βββ App.js
β β βββ App.css
β β βββ index.js
β β βββ index.css
β βββ .env # Environment Variables
β βββ package.json
βββ database/
β βββ schema.sql # Database schema
β βββ sample_data.sql # Sample data
βββ README.md
-
Login ke AWS Console
- Buka AWS Console
- Masuk ke service RDS
-
Create Database
- Klik "Create database"
- Pilih "Standard create"
- Engine type: MySQL
- Version: MySQL 8.0 (recommended)
-
Database Settings
DB instance identifier: product-db Master username: admin Master password: [buat password yang kuat] -
Instance Configuration
- DB instance class: db.t3.micro (Free tier eligible)
- Storage type: General Purpose SSD (gp2)
- Allocated storage: 20 GB
-
Connectivity
- Virtual Private Cloud (VPC): Default VPC
- Public access: Yes (untuk development)
- VPC security group: Buat baru atau gunakan yang ada
-
Database Options
Initial database name: product_db Port: 3306
-
Edit Security Group
- Masuk ke EC2 Console
- Pilih Security Groups
- Edit security group yang digunakan RDS
-
Add Inbound Rules
Type: MySQL/Aurora Protocol: TCP Port: 3306 Source: 0.0.0.0/0 (untuk development)β οΈ Warning: Untuk production, batasi source IP hanya untuk server aplikasi Anda!
# Install MySQL client (jika belum ada)
# macOS
brew install mysql-client
# Ubuntu/Debian
sudo apt install mysql-client
# CentOS/RHEL
sudo yum install mysql
# Test koneksi
mysql -h your-rds-endpoint.region.rds.amazonaws.com -P 3306 -u admin -p# Import schema
mysql -h your-rds-endpoint.region.rds.amazonaws.com -P 3306 -u admin -p < database/schema.sql
# Import sample data
mysql -h your-rds-endpoint.region.rds.amazonaws.com -P 3306 -u admin -p < database/sample_data.sql- Node.js (v16 atau lebih baru)
- npm atau yarn
- AWS RDS MySQL instance yang sudah running
- Git
git clone https://github.com/AbyanDimas/react-product-crud
cd react-product-crudcd backend
# Install dependencies
npm install
# Copy dan edit environment variables
cp .env.example .env
# Edit .env dengan konfigurasi RDS AndaEdit file backend/.env:
# Database Configuration untuk AWS RDS MySQL
DB_HOST=your-rds-endpoint.region.rds.amazonaws.com
DB_PORT=3306
DB_USER=admin
DB_PASSWORD=your-password
DB_NAME=product_db
# Server Configuration
PORT=5000
NODE_ENV=development
# CORS Configuration
FRONTEND_URL=http://localhost:3000cd ../frontend
# Install dependencies
npm install
# Environment variables sudah ter-konfigurasi di .env# Dari root directory
# Import schema
mysql -h your-rds-endpoint.region.rds.amazonaws.com -P 3306 -u admin -p < database/schema.sql
# Import sample data
mysql -h your-rds-endpoint.region.rds.amazonaws.com -P 3306 -u admin -p < database/sample_data.sqlTerminal 1 - Backend:
cd backend
npm run dev
# Server akan berjalan di http://localhost:5000Terminal 2 - Frontend:
cd frontend
npm start
# Aplikasi akan terbuka di http://localhost:3000Backend:
cd backend
npm startFrontend:
cd frontend
npm run build
# Deploy build folder ke web serverhttp://localhost:5000/api
| Method | Endpoint | Description | Parameters |
|---|---|---|---|
| GET | /products |
Get all products | page, limit, category, search |
| GET | /products/:id |
Get product by ID | - |
| POST | /products |
Create new product | Body: product data |
| PUT | /products/:id |
Update product | Body: product data |
| DELETE | /products/:id |
Delete product | - |
| GET | /categories |
Get all categories | - |
Get Products with Pagination:
GET /api/products?page=1&limit=10&category=Electronics&search=iPhoneCreate Product:
POST /api/products
Content-Type: application/json
{
"name": "iPhone 15 Pro",
"description": "Latest iPhone with A17 Pro chip",
"price": 15999000,
"category": "Electronics",
"stock_quantity": 50,
"image_url": "https://example.com/iphone15.jpg"
}Update Product:
PUT /api/products/1
Content-Type: application/json
{
"name": "iPhone 15 Pro Max",
"price": 18999000,
"stock_quantity": 30
}Success Response:
{
"success": true,
"message": "Products retrieved successfully",
"data": [...],
"pagination": {
"currentPage": 1,
"totalPages": 5,
"totalItems": 50,
"itemsPerPage": 10
}
}Error Response:
{
"success": false,
"message": "Error message",
"data": null
}| Column | Type | Description |
|---|---|---|
| id | INT AUTO_INCREMENT | Primary key |
| name | VARCHAR(255) | Product name (required) |
| description | TEXT | Product description |
| price | DECIMAL(10,2) | Product price (required) |
| category | VARCHAR(100) | Product category |
| stock_quantity | INT | Stock quantity (default: 0) |
| image_url | VARCHAR(500) | Product image URL |
| created_at | TIMESTAMP | Creation timestamp |
| updated_at | TIMESTAMP | Last update timestamp |
idx_products_nameonnameidx_products_categoryoncategoryidx_products_created_atoncreated_at
- Persiapan
cd backend
# Create Procfile
echo "web: node server.js" > Procfile
# Create Heroku app
heroku create your-app-name-backend
# Set environment variables
heroku config:set DB_HOST=your-rds-endpoint.region.rds.amazonaws.com
heroku config:set DB_PORT=3306
heroku config:set DB_USER=admin
heroku config:set DB_PASSWORD=your-password
heroku config:set DB_NAME=product_db
heroku config:set NODE_ENV=production
# Deploy
git add .
git commit -m "Initial backend deploy"
heroku git:remote -a your-app-name-backend
git push heroku main- Build untuk production
cd frontend
# Update .env untuk production
REACT_APP_API_URL=https://your-app-name-backend.herokuapp.com/api
# Build
npm run build- Deploy ke Netlify
- Drag & drop folder
buildke Netlify - Atau connect dengan Git repository
- Drag & drop folder
# Install Vercel CLI
npm i -g vercel
# Deploy
cd frontend
vercel
# Set environment variables di Vercel dashboardError: ECONNREFUSED atau ETIMEDOUT
Solutions:
- β Pastikan RDS instance sudah running
- β Check security group rules (port 3306 terbuka)
- β Verify endpoint URL dan credentials
- β Test koneksi dengan MySQL client
Error: Access-Control-Allow-Origin
Solutions:
- β
Pastikan
FRONTEND_URLdi backend.envsudah benar - β
Check CORS configuration di
server.js
Error: Cannot find module
Solutions:
- β
Run
npm installdi folder yang bermasalah - β
Delete
node_modulesdanpackage-lock.json, lalunpm install
Solutions:
- β Check Node.js version (gunakan v16+)
- β
Clear npm cache:
npm cache clean --force - β
Update dependencies:
npm update
# Check backend health
curl http://localhost:5000/health
# Check database connection
node -e "require('./backend/config/database').testConnection()"
# View backend logs
cd backend && npm run dev
# View frontend logs
cd frontend && npm start- β Gunakan indexes yang sudah ada
- β Implement database connection pooling
- β Add query caching untuk production
- β Implement lazy loading untuk images
- β Add loading states
- β Use React.memo untuk prevent unnecessary re-renders
- β Implement virtual scrolling untuk large datasets
- β Add response compression
- β Implement rate limiting
- β Use environment-based logging
- β Add API caching
- β Environment Variables: Semua sensitive data di environment variables
- β Database Security: Batasi IP access untuk RDS
- β HTTPS: Gunakan HTTPS untuk production
- β Input Validation: Validate semua input di frontend dan backend
- β SQL Injection: Gunakan prepared statements (sudah implemented)
- β CORS: Konfigurasi CORS dengan domain yang spesifik
- β Rate Limiting: Implement rate limiting untuk API
- β Authentication: Add user authentication untuk production use
- Fork repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
Distributed under the MIT License. See LICENSE for more information.
Jika ada pertanyaan atau issues:
- Check troubleshooting section di atas
- Create issue di GitHub repository
- Contact maintainer
π Selamat! Aplikasi Product CRUD Anda sudah siap digunakan!
Dengan mengikuti panduan ini, Anda telah berhasil membuat aplikasi CRUD yang lengkap dengan:
- β Modern React.js frontend
- β Robust Node.js/Express backend
- β AWS RDS MySQL database
- β Responsive design
- β Production-ready deployment
Aplikasi ini siap untuk dikembangkan lebih lanjut dengan fitur-fitur tambahan seperti authentication, file upload, atau integrasi dengan service AWS lainnya.