Skip to content

Repository files navigation

Starter

A minimal Node.js starter template with SQLite/PostgreSQL, Docker, and Fly.io deployment.

Documentation

  • README.md - This file. Setup, usage, and deployment instructions.
  • SPEC.md - Project-specific details: endpoints, structure, environment variables.
  • CLAUDE.md - Instructions for Claude Code AI assistant. Workflow and maintenance guidelines.
  • CHANGELOG.md - Project history, changes, and learnings.
  • GOTCHAS.md - Known issues, confusing behaviors, and post-mortems.
  • fly-deploy.md - Fly.io deployment reference and troubleshooting.

What's Included

  • Express.js server with health check endpoints
  • SQLite database (default) or PostgreSQL (optional)
  • Docker setup for local development
  • Fly.io configuration for production deployment
  • Status page at / showing server and database health

Prerequisites

  • Docker (required)
  • Node.js v20+ (optional, for local dev without Docker)
  • Fly CLI (for production deployment)
  • PostgreSQL running locally on port 5432 (only if using PostgreSQL mode)

Quick Start

git clone <this-repo> my-project
cd my-project
docker compose up --build

Open http://127.0.0.1:3000 to see the status page.

That's it! SQLite is the default -- no external database needed.

Database Options

This starter supports two database backends, chosen at project init time:

SQLite (default)PostgreSQL
Best forSimple apps, prototypes, MVPsMulti-user apps, complex queries
SetupZero configRequires PostgreSQL on host
Compose filedocker-compose.ymldocker-compose.postgres.yml
Fly.ioVolume + 1 machineManaged Postgres (MPG)

See CLAUDE.md "Step 0: Choose Database" for decision criteria.

Project Structure

src/
index.js # Express server with routes and status page
db.js # Database abstraction (SQLite/PostgreSQL)
healthcheck.js # Health check script for testing
scripts/
init-db.sh # Creates PostgreSQL database if needed
get-port.sh # Generates deterministic port from project name
Dockerfile # Production container image
docker-compose.yml # Local dev (SQLite mode)
docker-compose.postgres.yml # Local dev (PostgreSQL mode)
fly.toml # Fly.io deployment configuration
.claude/ # Claude Code settings

Configuration

Environment Variables

VariableDefaultDescription
PORT3000Server port (use ./scripts/get-port.sh for deterministic port)
DB_TYPEsqliteDatabase backend: sqlite or postgres
SQLITE_PATH./data/myapp.dbSQLite database file path
DATABASE_URL-PostgreSQL connection string (when DB_TYPE=postgres)
DB_NAMEmyappDatabase name for PostgreSQL init script

Customizing for Your Project

Replace myapp with your project name and set a deterministic port:

# On macOS
sed -i '''s/myapp/my-project-name/g' package.json docker-compose.yml .env.example
# Generate a deterministic port (avoids conflicts when running multiple projects)
PORT=$(./scripts/get-port.sh my-project-name)
sed -i ''"s/PORT=3000/PORT=$PORT/" .env.example
# Create your .env file
cp .env.example .env

Or manually update package.json, docker-compose.yml, and .env.example.

API Endpoints

EndpointDescription
GET /Status page showing server and database health
GET /healthJSON health check (server only)
GET /health/dbJSON health check (server + database, shows DB type)

Local Development

With Docker (Recommended)

# SQLite mode (default)
docker compose up --build
# PostgreSQL mode
docker compose -f docker-compose.postgres.yml up --build
# View logs
docker compose logs -f app
# Stop
docker compose down

Without Docker

# Install dependencies
npm install
# Create and configure .env
cp .env.example .env
# Start the server with auto-reload
npm run dev
# Test the health endpoint
npm test

Deploy to Fly.io

See fly-deploy.md for complete reference and troubleshooting.

SQLite Deployment

fly launch # Create app (say NO to Postgres, NO to deploy)
fly volumes create data --size 1 # Create volume for SQLite# Uncomment [mounts] section in fly.toml
fly scale count 1 # SQLite needs exactly 1 machine
fly deploy

PostgreSQL Deployment

fly launch # Create app (say NO to Postgres, NO to deploy)# Create Managed Postgres via Fly Dashboard
fly secrets set DATABASE_URL="..."# Set connection string
fly deploy

See fly-deploy.md for details.

Troubleshooting

Database connection failed (PostgreSQL mode)

  1. Make sure PostgreSQL is running on port 5432: pg_isready
  2. Check init-db logs: docker compose -f docker-compose.postgres.yml logs init-db
  3. On Fly.io, check DATABASE_URL: fly secrets list

Port already in use

Change the port in your .env file or docker-compose.yml.

Browser redirects to HTTPS

Use http://127.0.0.1:PORT instead of localhost. Or use an incognito window.

Scripts

CommandDescription
npm startStart the server
npm run devStart with auto-reload (Node.js --watch)
npm testRun health check against running server

License

MIT

About

starter repo for node.js + claude + fly

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages