Skip to main content

Running the Backend

The backend is a Node.js + Express 5 API server located in demo-server/. It runs on port 6600 and requires PostgreSQL and Redis.

Prerequisites​

  • PostgreSQL 18 running and accessible
  • Redis 6+ running locally (see Redis Setup)

1. Install dependencies​

cd demo-server
npm install

2. Configure environment​

cp .env.example .env

At minimum, fill in:

# Database
DB_HOST=localhost
DB_PORT=5432
DB_USER=your_user
DB_PASSWORD=your_password
DB_NAME=primesaas

# App
CLIENT_URL=http://localhost:3300
NODE_ENV=development

# Secrets (generate with: openssl rand -hex 32)
TOKEN_SECRET=your_jwt_secret
REFRESH_SECRET=your_refresh_secret

# Payment gateway (lemonsqueezy | stripe)
PAYMENT_GATEWAY=lemonsqueezy

See Database Setup and Lemon Squeezy Setup for the full configuration.

3. Run database migrations​

npm run migrate

This runs all Knex migrations in migrations/ against your database.

4. Start the dev server​

npm run dev

The API will be available at http://localhost:6600.

Production start​

npm run start

This runs migrations and then starts the server — safe to use as a deploy command.

API structure​

All routes are prefixed with /:

Route groupDescription
/authSign in, sign up, magic links, 2FA
/accountUser account management
/accountsMulti-tenant account management
/paymentsPayment history and invoices
/checkoutInitiate checkout flow
/subscriptionSubscription management
/plansPricing plan catalog
/api-keysAPI key CRUD
/webhooksCustomer-registered webhooks
/webhooks/stripeStripe payment webhooks
/webhooks/lemonsqueezyLemon Squeezy payment webhooks
/mediaFile upload and management
/healthHealth check endpoint

Tech stack​

  • Express 5 REST API
  • Knex.js query builder + migrations
  • Argon2 password hashing
  • JWT (access + refresh tokens)
  • BullMQ background job queues
  • Mailgun transactional email
  • AWS S3 file storage
  • Sentry error tracking