Langkah 1: Prasyarat
Install Node.js
Download dan install Node.js dari https://nodejs.org/
Verifikasi Instalasi
node --version
# Output: v20.x.x atau lebih tinggi
npm --version
# Output: 10.x.x atau lebih tinggiJika command tidak ditemukan, restart terminal atau tambahkan Node.js ke PATH.
Langkah 2: Install Node.js Server
Jalankan perintah berikut di root project:
cd C:\Tnserver\www
nxdom install nodecd /path/to/project
./nxdom install nodeApa yang Terjadi?
Perintah nxdom install node akan:
- ✅ Check apakah Node.js dan npm terinstall
- ✅ Check apakah
server.jsdanpackage.jsonsudah ada - ✅ Prompt konfirmasi jika file sudah ada (overwrite atau skip)
- ✅ Membuat file
server.jsdari template - ✅ Membuat file
package.jsondari template - ✅ Menjalankan
npm installuntuk install dependencies
File yang Dibuat
1. server.js
File utama Node.js server dengan Express dan proxy ke PHP API.
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const cors = require('cors');
// Di project nyata: PHP_SERVER dari resolvePhpServer()
// (.nxdom-php-port → PHP_SERVER → http://127.0.0.1:8000)
const app = express();
const PORT = process.env.PORT || 3000;
app.use(cors());
app.use(express.json());
app.use('/nx', createProxyMiddleware({
target: process.env.PHP_SERVER || 'http://127.0.0.1:8000',
changeOrigin: true,
pathRewrite: { '^/nx': '/api' }
}));
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date() });
});
app.listen(PORT, () => {
console.log(`Node.js server on port ${PORT}`);
});2. package.json
Konfigurasi dependencies dan scripts.
{
"name": "nexaui",
"version": "1.0.0",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"dependencies": {
"express": "^4.18.2",
"http-proxy-middleware": "^2.0.6",
"cors": "^2.8.5",
"helmet": "^7.1.0",
"morgan": "^1.10.0"
}
}3. node_modules/
Folder berisi semua dependencies yang terinstall. Folder ini di-ignore oleh Git.
Langkah 3: Konfigurasi .env
Buka file .env untuk dokumentasi konfigurasi Anda. server.js bawaan tidak memuat .env otomatis — nilai seperti PHP_SERVER diambil dari environment proses (termasuk yang diset nxdom.bat saat nxdom node).
Contoh isi referensi:
# Node.js Server Configuration
PORT=3000
PHP_SERVER=http://127.0.0.1:8000
NODE_ENV=development
# App Environment (untuk security)
APP_ENV=development| Variable | Default | Deskripsi |
|---|---|---|
PORT |
3000 | Port untuk Node.js server |
PHP_SERVER |
http://127.0.0.1:8000 (jika tidak ada file port) |
Origin PHP untuk proxy; di server.js asli dipilih via resolvePhpServer() |
NODE_ENV |
development | Environment mode Node.js |
APP_ENV |
development | Environment app (untuk security check) |
Langkah 4: Jalankan Server
Development Mode
nxdom node
# atau port Node lain, proxy ke Apache :80:
nxdom node 4000Output:
============================================
Starting Node.js Development Server
============================================
[INFO] Port: 3000
[INFO] Starting server...
Node.js server running on port 3000
[OK] Server started successfully!
[INFO] Press Ctrl+C to stopProduction Mode
nxdom node productionOutput:
============================================
Starting Node.js Production Server (PM2)
============================================
[INFO] Creating ecosystem.config.js...
[OK] ecosystem.config.js created
[INFO] Starting PM2 process...
[PM2] Starting server.js in cluster mode (2 instances)
[PM2] Done.
[OK] Production server started!
[INFO] Management commands:
pm2 status
pm2 logs nxdom-node
pm2 restart nxdom-node
pm2 stop nxdom-nodeLangkah 5: Test Server
Buka browser atau gunakan curl untuk test endpoints:
# Node.js health check
http://localhost:3000/api/health
# PHP API via proxy
http://localhost:3000/nx/testcurl http://localhost:3000/api/health
curl http://localhost:3000/nx/testLangkah 6: Jalankan PHP + Node.js Bersamaan
Disarankan (Windows): satu perintah — PHP built-in di jendela baru + Node di terminal saat ini:
nxdom devAtau Apache sudah menjalankan PHP (mis. http://localhost/api/...): jalankan saja nxdom node — proxy mengarah ke http://127.0.0.1. Jangan mengandalkan kombinasi nxdom start + nxdom node untuk menyamakan port built-in, karena nxdom node (bat) tidak membaca .nxdom-php-port untuk target proxy.
Setelah berjalan:
- ✅ PHP (built-in atau Apache sesuai setup Anda)
- ✅ Node.js API:
http://localhost:3000/api/health - ✅ PHP via proxy Node:
http://localhost:3000/nx/...
Uninstall (Optional)
Jika ingin menghapus Node.js server:
nxdom uninstall node- Perintah ini akan menghapus
server.js,package.json,node_modules/, danecosystem.config.js - Hanya dapat dijalankan di mode
APP_ENV=development - Akan menghentikan semua Node.js processes terlebih dahulu
- Memerlukan konfirmasi sebelum menghapus
Troubleshooting Instalasi
Node.js tidak ditemukan
[ERROR] Node.js is not installed
[INFO] Please install Node.js from https://nodejs.org/Solusi:
- Download Node.js installer dari https://nodejs.org/
- Jalankan installer dan ikuti petunjuk
- Restart terminal/PowerShell
- Verifikasi:
node --version
npm install gagal
npm ERR! network timeoutSolusi:
- Check koneksi internet
- Coba lagi:
npm install - Gunakan registry mirror:
npm install --registry=https://registry.npmmirror.com
File sudah ada
[WARNING] server.js already exists
Do you want to overwrite? (Y/N):Pilihan:
Y- Overwrite file yang ada (backup manual dulu jika perlu)N- Skip, gunakan file yang sudah ada
Permission denied (Linux/macOS)
bash: ./nexa: Permission deniedSolusi:
chmod +x nexa
./nxdom install nodeStruktur File Setelah Install
C:\Tnserver\www\
├── server.js # Node.js server (baru)
├── package.json # Dependencies config (baru)
├── node_modules/ # Dependencies (baru)
├── .env # Environment variables
├── .gitignore # Ignore node_modules
├── nxdom.bat # CLI Windows
├── nexa # CLI Linux/macOS
├── controllers/ # PHP Controllers
│ └── Api/ # PHP API Controllers
├── system/
│ └── bin/
│ ├── templates/
│ │ ├── server.js.template
│ │ └── package.json.template
│ ├── nxdom-install-node.bat
│ └── nxdom-install-node.sh
└── templates/ # ViewsDependencies yang Terinstall
| Package | Versi | Deskripsi |
|---|---|---|
express |
^4.18.2 | Web framework untuk Node.js |
http-proxy-middleware |
^2.0.6 | Proxy middleware untuk routing ke PHP |
cors |
^2.8.5 | Enable Cross-Origin Resource Sharing |
helmet |
^7.1.0 | Security headers middleware |
morgan |
^1.10.0 | HTTP request logger |
dotenv |
^16.3.1 | Load environment variables dari .env |
mysql2 |
^3.6.0 | MySQL client (optional) |
nodemon |
^3.0.1 | Auto-restart saat development (devDependency) |
Verifikasi Instalasi
1. Check File
dir server.js
dir package.json
dir node_modulesls -la server.js
ls -la package.json
ls -la node_modules2. Test Server
# Start server
nxdom node
# Di terminal lain, test endpoint
curl http://localhost:3000/api/healthResponse yang diharapkan:
{
"status": "ok",
"message": "NexaUI Node.js server is running",
"timestamp": "2026-03-31T10:30:00.000Z",
"phpServer": "http://127.0.0.1:8000"
}Reinstall Dependencies
Jika node_modules/ terhapus atau corrupt:
# Hapus node_modules dan package-lock.json
rm -rf node_modules package-lock.json
# Install ulang
npm installUpdate Dependencies
Untuk update dependencies ke versi terbaru:
# Check outdated packages
npm outdated
# Update semua
npm update
# Update specific package
npm install express@latestNext Steps
- Pelajari API Proxy untuk routing ke PHP
- Pelajari Static Files untuk serving images/assets
- Setup Production Deployment dengan PM2
- Tambahkan custom endpoints di
server.js