page:guides:express:database connection

Connect Postgres for Express

Connect an Express app to PostgreSQL on Ample. Read DATABASE_URL at runtime: when you supply one with --env it is delivered encrypted and takes precedence; when you supply none and the app needs PostgreSQL, Ample auto-provisions a managed PostgreSQL 16 database and injects its connection string.

Representative Queries

Prerequisites

Workflow Steps

  1. Read the URL at runtime
    Construct the pg Pool from process.env.DATABASE_URL inside the app; never commit credentials.
  2. Choose the source of the database
    Pass --env DATABASE_URL=... for an existing database, or omit it to let Ample provision a managed one on first deploy and reuse it on redeploys.
    ample deploy . --name  --public --env DATABASE_URL=postgres://...
    
  3. Test the connection through the app
    Expose a route that runs a trivial query and returns postgres=ok, then deploy and fetch it.
  4. Verify
    Fetch the live URL and run the success checks below. On failure read the build log, then the runtime log, fix the cause and deploy again; do not blind-retry.
    ample logs  --kind build
    

Examples

Success Checks

Limitations

Cost Estimate

Components

  1. App server
    • Size: s-1vcpu-1gb
    • Quantity: 1.0
    • Monthly Amount: 5.0
  2. Managed PostgreSQL database
    • Size: s-1vcpu-1gb
    • Quantity: 1.0
    • Monthly Amount: 5.0

Note: Apps and managed databases auto-pause when idle; the estimate is the always-on monthly price of the tested sizes. Plan quotas and budgets apply.