Skip to main content

start-backend.sh

Starts only the backend Node.js server.

Purpose

Lightweight script to start the backend independently without the frontend.

Location

Must be run from the scripts/ directory:

cd scripts
./start-backend.sh

What It Does

  1. Validates build - Checks that backend/dist/ exists, builds if missing
  2. Validates .env - Ensures configuration file exists
  3. Validates API key - Checks that OPENAI_API_KEY is set and not a placeholder
  4. Starts server - Runs npm start in backend directory

Prerequisites

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

Output

Starting AI content reporpuser Backend...
Starting server on port 3000...

Server running on port 3000
Admin SDK initialized successfully

Press Ctrl+C to stop.

Environment Validation

The script validates that:

  1. .env file exists
  2. OPENAI_API_KEY is present
  3. API key is not the placeholder value your_openai_api_key_here

If validation fails:

Error: OPENAI_API_KEY is not set in backend/.env
Please set a valid OpenAI API key before starting the backend.

Port Configuration

Default port is 3000. To change:

Edit backend/.env:

PORT=3001

Troubleshooting

Port already in use

# Find process using port 3000
lsof -ti:3000

# Kill it
lsof -ti:3000 | xargs kill

# Or change port in .env
PORT=3001

Build not found

cd backend
npm run build

API key error

Edit backend/.env:

OPENAI_API_KEY=sk-...your-real-key...

Get your key from: https://platform.openai.com/api-keys

Logs

Backend logs to console by default. For production logging, see backend/logs/.

When to Use

Use this script when:

  • Testing backend API independently
  • Developing backend without frontend
  • Running backend on a server
  • Debugging backend issues

For full development with frontend, use ./start-dev.sh instead.

Source Code

Located at: scripts/start-backend.sh

Key features:

  • Automatic build check
  • API key validation
  • Simple error messages
  • Fast startup