cd /home/ubuntu/name-normalization-demo
./scripts/restart-server.shThis script automatically:
- ✅ Kills all existing server processes
- ✅ Frees up port 3000
- ✅ Cleans up stuck Redis jobs
- ✅ Starts the server in the background
- ✅ Waits for server to be ready
- ✅ Verifies health check passes
cd /home/ubuntu/name-normalization-demo
./scripts/health-check.shThis shows:
- Server status (healthy/unhealthy)
- Uptime
- Memory usage
- Process ID
- Whether server is responding
cd /home/ubuntu/name-normalization-demo
pnpm dev# Kill by process name
pkill -f "tsx watch server/_core/index.ts"
# Or kill by port
lsof -ti:3000 | xargs kill -9# If started with restart-server.sh
tail -f /tmp/server.log
# If started manually, logs are in terminalThe server now has a health check endpoint at:
GET http://localhost:3000/api/health
Response Example:
{
"status": "ok",
"timestamp": "2025-11-18T00:31:32.717Z",
"uptime": 10.547,
"memory": {
"rss": 441020416,
"heapTotal": 197132288,
"heapUsed": 165453448
},
"pid": 163018
}Use this to:
- Monitor server status programmatically
- Set up automated health checks
- Debug server issues
The server now includes:
- Uncaught exceptions are logged but don't crash the server
- Unhandled promise rejections are logged but don't crash the server
- All errors are logged with full stack traces
- Job queue failures don't crash the server
- CRM merge worker failures don't crash the server
- Connection pool errors don't crash the server
- Port conflicts are detected and handled
- Server errors are logged with details
Problem: Port 3000 is already in use
Solution:
# Kill process using port 3000
lsof -ti:3000 | xargs kill -9
# Then restart
./scripts/restart-server.shProblem: Unhandled errors causing crashes
Solution:
-
Check server logs for error messages:
tail -100 /tmp/server.log
-
Look for error patterns:
[FATAL] Uncaught Exception:- Synchronous error[ERROR] Unhandled Promise Rejection:- Async error[CRMMergeWorker] Job failed:- Job processing error
-
Share the error message for debugging
Problem: Server process running but not responding
Solution:
# Check if server is responding
./scripts/health-check.sh
# If unhealthy, restart
./scripts/restart-server.shProblem: Jobs not processing, Redis errors
Solution:
# Check if Redis is running
redis-cli ping
# If not responding, start Redis
redis-server &
# Clear stuck jobs
redis-cli KEYS "bull:*:stalled" | xargs redis-cli DEL
# Restart server
./scripts/restart-server.sh# Check server health
./scripts/health-check.sh
# Restart server (foolproof)
./scripts/restart-server.sh
# View live logs
tail -f /tmp/server.log
# Check memory usage
ps aux | grep node | grep -v grep
# Check port usage
lsof -i :3000
# Test health endpoint
curl http://localhost:3000/api/health | python3 -m json.toolThe health endpoint shows memory usage. Watch for:
- heapUsed growing continuously (memory leak)
- rss (Resident Set Size) > 1GB (high memory usage)
The health endpoint shows uptime in seconds. If uptime resets frequently, the server is crashing.
The health endpoint shows the process ID. If this changes, the server has restarted.
If everything fails:
# Nuclear option: kill everything and restart
pkill -9 -f "tsx"
pkill -9 -f "node"
sleep 2
cd /home/ubuntu/name-normalization-demo
./scripts/restart-server.shIf the server continues to crash:
-
Capture the error logs:
tail -200 /tmp/server.log > server-error.log -
Check the health status:
./scripts/health-check.sh > health-status.txt -
Share both files for debugging
- Always use the restart script instead of manually killing processes
- Check health before and after making changes
- Monitor memory usage if processing large files
- Clear stuck Redis jobs if jobs aren't processing
- Keep logs when debugging issues