lapeh 2.4.5 → 2.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/doc/DEPLOYMENT.md +102 -1
- package/package.json +1 -1
package/doc/DEPLOYMENT.md
CHANGED
|
@@ -49,21 +49,25 @@ npm run prisma:deploy
|
|
|
49
49
|
Lapeh kini menyertakan konfigurasi otomatis PM2 (`ecosystem.config.js`).
|
|
50
50
|
|
|
51
51
|
1. **Install PM2 Global**:
|
|
52
|
+
|
|
52
53
|
```bash
|
|
53
54
|
npm install -g pm2
|
|
54
55
|
```
|
|
55
56
|
|
|
56
57
|
2. **Jalankan Aplikasi**:
|
|
58
|
+
|
|
57
59
|
```bash
|
|
58
60
|
pm2 start ecosystem.config.js
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
Perintah ini akan:
|
|
64
|
+
|
|
62
65
|
- Menjalankan aplikasi dalam mode **Cluster** (menggunakan semua core CPU yang tersedia).
|
|
63
66
|
- Mengatur `NODE_ENV` ke `production`.
|
|
64
67
|
- Mengaktifkan auto-restart jika aplikasi crash atau penggunaan memori melebihi 1GB.
|
|
65
68
|
|
|
66
69
|
3. **Cek Status**:
|
|
70
|
+
|
|
67
71
|
```bash
|
|
68
72
|
pm2 status
|
|
69
73
|
pm2 logs
|
|
@@ -75,7 +79,104 @@ Lapeh kini menyertakan konfigurasi otomatis PM2 (`ecosystem.config.js`).
|
|
|
75
79
|
pm2 startup
|
|
76
80
|
```
|
|
77
81
|
|
|
78
|
-
###
|
|
82
|
+
### ❓ FAQ: Mengapa Aplikasi Saya Muncul Ganda di PM2?
|
|
83
|
+
|
|
84
|
+
Jika Anda menjalankan `pm2 list` dan melihat nama aplikasi Anda muncul lebih dari satu kali (misal: `my-app` ada 2 atau 4 baris), **JANGAN KHAWATIR**. Ini adalah fitur, bukan bug.
|
|
85
|
+
|
|
86
|
+
- **Penyebab**: Konfigurasi `instances: "max"` dan `exec_mode: "cluster"` di `ecosystem.config.js`.
|
|
87
|
+
- **Fungsi**: PM2 mendeteksi jumlah inti CPU (Core) di VPS Anda dan membuat 1 proses worker untuk setiap core.
|
|
88
|
+
- Jika VPS punya 2 vCPU -> Muncul 2 proses.
|
|
89
|
+
- Jika VPS punya 4 vCPU -> Muncul 4 proses.
|
|
90
|
+
- **Keuntungan**: Aplikasi Anda menjadi **Multi-Threaded**. Request yang masuk akan dibagi rata ke semua proses, meningkatkan performa 2x-4x lipat dibanding mode biasa.
|
|
91
|
+
|
|
92
|
+
**Cara mengubah ke Single Instance (Hemat RAM):**
|
|
93
|
+
Jika RAM server Anda terbatas (misal 512MB/1GB) dan ingin menghemat resource, ubah `ecosystem.config.js`:
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
module.exports = {
|
|
97
|
+
apps: [
|
|
98
|
+
{
|
|
99
|
+
name: "my-app",
|
|
100
|
+
// ...
|
|
101
|
+
instances: 1, // Ubah "max" menjadi 1
|
|
102
|
+
// ...
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Lalu jalankan `pm2 reload ecosystem.config.js`.
|
|
109
|
+
|
|
110
|
+
### 7. Advanced: Menjalankan Beberapa Aplikasi (Multi-App)
|
|
111
|
+
|
|
112
|
+
Jika Anda memiliki beberapa aplikasi Node.js dalam satu VPS (misalnya: Backend API, Frontend React SSR, dan API Lapeh), Anda bisa menggabungkannya dalam satu file `ecosystem.config.js`.
|
|
113
|
+
|
|
114
|
+
Berikut adalah contoh konfigurasi **Real World** untuk menjalankan 3 aplikasi sekaligus:
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
module.exports = {
|
|
118
|
+
apps: [
|
|
119
|
+
// 1. APLIKASI LAIN (Contoh: Backend MERN)
|
|
120
|
+
{
|
|
121
|
+
name: "api-mern-news",
|
|
122
|
+
cwd: "/var/www/html/node/api-mern-news",
|
|
123
|
+
script: "dist/src/index.js",
|
|
124
|
+
env: {
|
|
125
|
+
NODE_ENV: "production",
|
|
126
|
+
PORT: 4000,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
// 2. APLIKASI LAIN (Contoh: Frontend React/Next.js)
|
|
131
|
+
{
|
|
132
|
+
name: "web-mern-news",
|
|
133
|
+
cwd: "/var/www/html/node/web-mern-news",
|
|
134
|
+
script: "npm",
|
|
135
|
+
args: "start", // Menjalankan 'npm start'
|
|
136
|
+
env: {
|
|
137
|
+
NODE_ENV: "production",
|
|
138
|
+
PORT: 3001,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// 3. APLIKASI LAPEH FRAMEWORK
|
|
143
|
+
{
|
|
144
|
+
name: "api-lapeh-project",
|
|
145
|
+
cwd: "/var/www/html/node/my-lapeh-project",
|
|
146
|
+
|
|
147
|
+
// PENTING: Gunakan binary Lapeh dari node_modules lokal
|
|
148
|
+
script: "./node_modules/lapeh/bin/index.js",
|
|
149
|
+
|
|
150
|
+
// Argument 'start' untuk mode produksi
|
|
151
|
+
args: "start",
|
|
152
|
+
|
|
153
|
+
// Mode Cluster (Gunakan semua Core CPU)
|
|
154
|
+
instances: "max",
|
|
155
|
+
exec_mode: "cluster",
|
|
156
|
+
|
|
157
|
+
// Restart jika memori bocor > 1GB
|
|
158
|
+
max_memory_restart: "1G",
|
|
159
|
+
|
|
160
|
+
// Matikan watch di production
|
|
161
|
+
watch: false,
|
|
162
|
+
|
|
163
|
+
env: {
|
|
164
|
+
NODE_ENV: "production",
|
|
165
|
+
PORT: 8001,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
};
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Tips:**
|
|
173
|
+
|
|
174
|
+
1. Sesuaikan `cwd` (Current Working Directory) dengan lokasi folder proyek Anda di VPS.
|
|
175
|
+
2. Pastikan port tidak bentrok antar aplikasi (contoh di atas: 4000, 3001, 8001).
|
|
176
|
+
3. Simpan file ini di root folder proyek utama atau di folder khusus konfigurasi server Anda.
|
|
177
|
+
4. Jalankan semua aplikasi sekaligus dengan: `pm2 start ecosystem.config.js`.
|
|
178
|
+
|
|
179
|
+
### 8. Reverse Proxy (Nginx)
|
|
79
180
|
|
|
80
181
|
Jangan expose port 4000 langsung. Gunakan Nginx di depannya.
|
|
81
182
|
Config Nginx block:
|