{"catalogRevision":"cat_f13ab9a494120b5e","recipeId":"page:guides:express:database-connection","recipeRevision":"r1","canonicalPath":"/guides/express/database-connection","label":"Connect Postgres for Express","family":"Framework operation","summary":"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.","representativeQueries":["Connect Postgres for Express","Where can I host Connect Postgres built with Express?","I need driver setup, connection settings, secret handling and a real connection test."],"breadcrumbIds":["discovery","stack","stack:frameworks","stack:framework-express","page:guides:express:database-connection"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"stack","label":"Frameworks and execution targets","canonicalPath":"/discover/stack","kind":"facet"},{"id":"stack:frameworks","label":"Frameworks","canonicalPath":"/discover/stack/frameworks","kind":"group"},{"id":"stack:framework-express","label":"Express","canonicalPath":"/discover/stack/framework-express","kind":"atom"},{"id":"page:guides:express:database-connection","label":"Connect Postgres for Express","canonicalPath":"/guides/express/database-connection","kind":"recipe"}],"parentIds":["stack:framework-express","intent:connect-app-to-database","pattern:relational-records"],"parents":[{"id":"stack:framework-express","label":"Express","canonicalPath":"/discover/stack/framework-express","kind":"atom"},{"id":"intent:connect-app-to-database","label":"Connect app to database","canonicalPath":"/discover/intent/connect-app-to-database","kind":"atom"},{"id":"pattern:relational-records","label":"Relational records","canonicalPath":"/discover/pattern/relational-records","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:postgres"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes."},{"primitiveId":"primitive:postgres","label":"Postgres","canonicalPath":"/discover/primitive/postgres","status":"verified","summary":"Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied."}],"framework":"Express","workload":"Connect Postgres","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["The pg driver reading process.env.DATABASE_URL","Either a production DATABASE_URL to pass with --env, or nothing (auto-provision)","An Ample account token with servers:write and databases:read"],"testedConfiguration":{"template":"node-22","runtime":"node","size":"s-1vcpu-1gb","install":"npm install","build":"npm run build --if-present","start":"npm run start"},"inputSchema":{"additionalProperties":false,"properties":{"env":{"description":"Encrypted environment variables as KEY=value; secret values are never stored in ample.toml","items":{"pattern":"^[A-Z][A-Z0-9_]*=.*$","type":"string"},"maxItems":50,"type":"array"},"name":{"description":"App name (lowercase, digits and dashes)","maxLength":63,"minLength":1,"pattern":"^[a-z0-9-]+$","type":"string"},"path":{"description":"Project directory to deploy, or one service name from ample.toml","maxLength":512,"minLength":1,"type":"string"},"size":{"description":"VM size; omit to let Ample pick a runtime-safe size","enum":["s-1vcpu-256mb","s-1vcpu-1gb","s-1vcpu-2gb","s-2vcpu-2gb","s-2vcpu-4gb"],"type":"string"}},"required":["name","path"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Read the URL at runtime","body":"Construct the pg Pool from process.env.DATABASE_URL inside the app; never commit credentials."},{"title":"Choose the source of the database","body":"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.","command":"ample deploy . --name <app-name> --public --env DATABASE_URL=postgres://..."},{"title":"Test the connection through the app","body":"Expose a route that runs a trivial query and returns postgres=ok, then deploy and fetch it."},{"title":"Verify","body":"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.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"Express + pg canary","description":"Auto-provisioned managed database with a real insert and count.","sourceRef":"tests/deploy-canaries/express-postgres-api"},{"title":"Supplied DATABASE_URL","description":"An explicit connection string delivered as an encrypted environment variable.","sourceRef":"tests/deploy-canaries/env-database-url"}],"successChecks":[{"description":"database route reports a live connection","kind":"http_get","path":"/items","expect":"postgres=ok"}],"limitations":["Verified on the node-22 template at s-1vcpu-1gb; other templates and sizes are not verified by this recipe.","Region, compliance attestations and request-duration limits are unknown and not claimed.","Apps auto-pause when idle and wake on the next request; always-on is an operator setting, not a plan feature.","Managed PostgreSQL 16 only; extensions, connection limits and backup or restore procedures are not verified.","Apps and their managed databases are placed together; cross-node shared databases are unsupported.","A supplied URL is used as-is; Ample does not validate reachability of external databases before the release starts."],"costEstimate":{"currency":"USD","monthlyAmount":10.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 752d2a7584688a5d233b2c53d38307d289b04d3e","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0},{"name":"managed PostgreSQL database","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":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."},"evidenceSummary":[{"kind":"canary_run","summary":"Express REST API using pg with no DATABASE_URL supplied: Ample auto-provisioned a managed PostgreSQL 16 database, injected the connection string, and /items reported postgres=ok after a real insert and count.","observedAt":"2026-09-19T23:55:33Z","implementationRevision":"1764076-tls-account-903d345","expiresAt":"2027-03-18T23:55:33Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}},{"kind":"canary_run","summary":"Node app needing PostgreSQL with no DATABASE_URL: a managed database was auto-provisioned and /db reported postgres=ok.","observedAt":"2026-09-19T23:55:33Z","implementationRevision":"1764076-tls-account-903d345","expiresAt":"2027-03-18T23:55:33Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}},{"kind":"canary_run","summary":"A supplied DATABASE_URL was delivered as an encrypted environment variable; the app saw the configured host and the secret was never echoed by the platform.","observedAt":"2026-09-19T23:55:33Z","implementationRevision":"1764076-tls-account-903d345","expiresAt":"2027-03-18T23:55:33Z","scope":{"cliVersion":"0.1.20","platform":"hosted","template":"node-22"}}],"lastVerifiedAt":"2026-09-19T23:55:33Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"876465fce906da0c224d62961d3343064108ebe30af80cf1b87094974e948853","observedAt":"2026-09-20T01:55:48.667900+00:00","implementationRevision":"199ff1dfd526","requiredScopes":["servers:write","databases:read"],"bindingState":"current"},"unknowns":["region availability is unknown until a verified region fact is recorded","compliance attestations are unknown; none are claimed"],"formats":{"html":"https://ample.computer/guides/express/database-connection","markdown":"https://ample.computer/guides/express/database-connection.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Aexpress%3Adatabase-connection"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Connect Postgres for Express"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:guides:express:database-connection","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:guides:express:database-connection","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-express","label":"Browse Express","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-express","origin":"api","parameters":{"nodeId":"stack:framework-express"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:connect-app-to-database","label":"Browse Connect app to database","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Aconnect-app-to-database","origin":"api","parameters":{"nodeId":"intent:connect-app-to-database"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:relational-records","label":"Browse Relational records","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Arelational-records","origin":"api","parameters":{"nodeId":"pattern:relational-records"},"requiresAuthentication":false,"requiresApproval":false}]}