# Start the server (production mode - default)
./server.sh start
# Start in development mode
./server.sh start dev
# Start in production mode (explicit)
./server.sh start prod
# Stop the server
./server.sh stop
# Restart the server
./server.sh restart
# Check server status and environment
./server.sh status
# Show environment and available configs
./server.sh env
# View logs (default: 50 lines)
./server.sh logs
# View more logs
./server.sh logs 100
# Remove PID lock (if server crashed)
./server.sh unlock
ngdpbase uses different configuration files based on the NODE_ENV environment variable:
| Environment | Config File | Use Case |
|---|---|---|
| **production** | config/app-production-config.json | Production deployment (default) |
| **development** | config/app-development-config.json | Local development |
| **test** | config/app-test-config.json | Running tests |
| **staging** | config/app-staging-config.json | Staging server (if exists) |
| **custom** | config/app-custom-config.json | Local overrides (not tracked in git) |
config/app-default-config.json is always loaded first (base settings)NODE_ENV, loads environment-specific configconfig/app-custom-config.json is loaded last and overrides everything.gitignored for local-only settings./server.sh argument (recommended)./server.sh start dev # Development mode
./server.sh start prod # Production mode
./server.sh restart dev # Restart in development mode
NODE_ENV=development ./server.sh start
NODE_ENV=staging ./server.sh start
NODE_ENV=production ./server.sh start
npm run start:dev # Development
npm run start:prod # Production
npm start # Production (default)
./server.sh env
The server uses a PID lock file (.ngdpbase.pid) to prevent multiple instances from running simultaneously. This ensures:
Check if server is actually running:
bash
./server.sh status
# or
ps aux | grep "node app.js" | grep -v grep
If server is running but shouldn't be:
bash
./server.sh stop
If server crashed and lock file is stale:
bash
./server.sh unlock
./server.sh start
All logs are written to the ./data/logs/ directory:
| Type | Location | Purpose |
|---|---|---|
| PM2 Output | ./data/logs/pm2-out.log | stdout, startup messages |
| PM2 Errors | ./data/logs/pm2-error.log | stderr, runtime errors |
| PM2 Combined | ./data/logs/pm2-combined.log | Combined PM2 logs |
| Application | ./data/logs/app.log | Winston logger, detailed operations |
| Audit | ./data/logs/audit.log | Security/audit events |
# Start
pm2 start npm --name "ngdpbase" -- start
# Stop
pm2 stop ngdpbase
# Restart
pm2 restart ngdpbase
# View logs
pm2 logs ngdpbase
# Delete from PM2
pm2 delete ngdpbase
# Start (will fail if another instance is running)
npm start
# Stop (Ctrl+C in terminal)
Solution 1: Check if another instance is actually running
pm2 list
ps aux | grep "node app.js"
Solution 2: Stop all instances
pm2 stop all
pkill -f "node app.js"
Solution 3: Remove stale PID lock
./server.sh unlock
Cause: Multiple server instances were running, saving to different instances.
Prevention: Always use ./server.sh or PM2 to manage the server. The PID lock prevents this issue.
Cause: Another application or orphaned Node process is using port 3000.
Solution:
# Find what's using port 3000
lsof -i :3000
# Kill the process (replace PID with actual process ID)
kill -9 <PID>
For production, use PM2 with the ecosystem file:
# Start with PM2
pm2 start ecosystem.config.js
# Save PM2 configuration
pm2 save
# Enable PM2 startup on system boot
pm2 startup
.ngdpbase.pid in the project root./server.sh unlock if needed