# 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) then `node dist/main.js` on 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
1. **Build and start**  
   `npm install`, `nest build` (TypeScript) then `node dist/main.js` on the node-22 template; the server must bind 0.0.0.0 on PORT.
2. **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.
3. **Verify**  
   Fetch the live URL and `/p/relational-records` on 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 patterns` at path `/`.
- **Relational records check from the example**  
   Expect: `see the pattern fixture checks` at 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
- **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.

## Next Actions
- [Browse the catalog index](https://api.ample.computer/v1/catalog)  
- [Search published recipes by intent, stack and constraints](https://api.ample.computer/v1/catalog/search)  
- [Prepare a side-effect-free deployment plan for an authorized project](https://api.ample.computer/v1/catalog/plan)  
- [Read the existing agent authentication setup](https://api.ample.com/mcp/setup)  
- [Browse NestJS](https://api.ample.com/v1/catalog/nodes/stack%3Aframework-nestjs)  
- [Browse Connect app to database](https://api.ample.com/v1/catalog/nodes/intent%3Aconnect-app-to-database)  
- [Browse Relational records](https://api.ample.com/v1/catalog/nodes/pattern%3Arelational-records)
