Skip to main content

start-dev.sh

Starts both backend and frontend in development mode with monitoring, logging, and health checks.

Purpose

The all-in-one development script that manages both services, monitors their health, and provides centralized logging.

Location

Must be run from the scripts/ directory:

cd scripts
./start-dev.sh

What It Does

  1. Stops existing services - Cleans up any running instances
  2. Validates setup - Checks that both backend and frontend are configured
  3. Starts backend - Launches Node.js server on port 3000
  4. Waits for backend - Polls health endpoint until ready
  5. Starts frontend - Launches Flutter app for your platform
  6. Monitors processes - Watches both services and restarts on failure
  7. Handles shutdown - Cleanly stops both on Ctrl+C

Prerequisites

  • Backend setup completed (./setup-backend.sh)
  • Frontend setup completed (./setup-frontend.sh)
  • Valid backend/.env with OpenAI API key

Output

Backend started (PID: 12345)
Logs: logs/backend.log
API: http://localhost:3000

✓ Backend is ready

Frontend started (PID: 12346)
Logs: logs/frontend.log
Platform: linux

Development Environment Running!

Backend: http://localhost:3000
Frontend: Running on linux

Logs:
tail -f logs/backend.log
tail -f logs/frontend.log

Press Ctrl+C to stop both services

Logs

All output is captured in:

  • logs/backend.log - Backend server logs
  • logs/frontend.log - Flutter app logs

View in real-time:

# Backend
tail -f logs/backend.log

# Frontend
tail -f logs/frontend.log

# Both
tail -f logs/backend.log logs/frontend.log

Process Management

The script creates PID files:

  • /tmp/ai-repurposer-backend.pid
  • /tmp/ai-repurposer-frontend.pid

This allows the script to:

  • Detect and stop existing processes
  • Monitor for crashes
  • Clean up on exit

Platform Detection

Auto-detects your platform:

  • Linux
  • macOS
  • Windows

Health Checks

Before starting the frontend, the script:

  1. Waits for backend to respond at http://localhost:3000/health
  2. Retries up to 15 times (30 seconds total)
  3. Exits with error if backend doesn't respond

Stopping Services

Press Ctrl+C to stop both services cleanly.

The script will:

  1. Kill backend process
  2. Kill frontend process
  3. Remove PID files
  4. Exit gracefully

Troubleshooting

Backend fails to start

Check logs:

cat logs/backend.log

Common issues:

  • Port 3000 already in use
  • Invalid .env configuration
  • Missing OpenAI API key

Frontend fails to start

Check logs:

cat logs/frontend.log

Common issues:

  • Backend not running
  • Flutter not configured
  • Platform support not enabled

Port already in use

Kill existing process:

lsof -ti:3000 | xargs kill

Or change port in backend/.env:

PORT=3001

Source Code

Located at: scripts/start-dev.sh

Key features:

  • Background process management
  • Automatic health checks
  • Centralized logging
  • Graceful shutdown
  • Process monitoring and restart
  • Platform-aware frontend launching