page:guides:nestjs:database connection
Connect Postgres for NestJS
Summary
Database connection for a NestJS app on Ample. Verified on NestJS: a managed PostgreSQL database auto-provisioned and injected as DATABASE_URL, with real queries succeeding at request time (records=ok). Build and start: npm install, nest build (TypeScript) then node dist/main.js on the node-22 template.
Resources
- Framework: NestJS
- Workload: Connect Postgres
- Release Status: Published
- Support Status: Verified
- Execution Status: Ready
- Docs Only: false
Prerequisites
- A NestJS project (
npm install,nest build(TypeScript) thennode dist/main.json the node-22 template) - A PostgreSQL driver reading DATABASE_URL at runtime
- An Ample account token with
servers:write,databases:read
Infrastructure Requirements
- Compute: Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.
- Postgres: Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.
Workflow Steps
- Build and start
npm install,nest build(TypeScript) thennode dist/main.json the node-22 template; the server must bind 0.0.0.0 on PORT. - Read DATABASE_URL at runtime
Open connections from the environment inside handlers or a pool; omit DATABASE_URL to auto-provision a managed database or pass--env DATABASE_URL=...for an existing one. - Verify
Fetch the live URL and/p/relational-recordson the example; on failure read the build and runtime logs. Command:ample logs --kind build
Examples
- NestJS pattern fixture
Verified database connection on NestJS. Source reference:tests/deploy-canaries/nestjs-patterns
Success Checks
- App responds on its public URL
Expect:ample canary nestjs patternsat path/. - Relational records check from the example
Expect:see the pattern fixture checksat path/p/relational-records.
Limitations
- Verified on the node-22 template at s-1vcpu-1gb; other sizes and NestJS major versions are not verified.
- Region, compliance attestations and request-duration limits are unknown and not claimed.
- Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.
Cost Estimate
- Currency: USD
- Monthly Amount: 10.0
- Basis: Size prices from pricing.toml (loaded by the API) at build revision 1ac5595375130d45290090e82ed0f554ccd45405-dirty.
- Components:
- App server: size:
s-1vcpu-1gb, quantity: 1.0, monthly amount: 5.0 - Managed PostgreSQL database: size:
s-1vcpu-1gb, quantity: 1.0, monthly amount: 5.0
- App server: size:
- Note: Always-on monthly price of the tested sizes; apps auto-pause when idle.
Evidence Summary
- Kind: canary_run
Summary: NestJS pattern fixture deployed on Ample. Observed at: 2026-09-21T02:34:39Z.