Deployment · By Rivtor · Updated
Deploy NestJS with PostgreSQL: builds, migrations and health
Build NestJS to its production JavaScript entrypoint, bind the HTTP server to the assigned interface and port, and read PostgreSQL configuration from the server environment. Run reviewed migrations separately and verify a database-backed route after release.
See the Rivtor deployment workflow →
Build an artifact the production command can start
A typical NestJS service contains package.json, a lockfile, src/main.ts and TypeScript configuration. Confirm the actual emitted file location after a clean build; monorepos and custom compiler settings can produce a different path from dist/main.js. Keep runtime dependencies in dependencies rather than relying on a development-only installation.
The following fragment belongs inside the existing bootstrap function, after creating the Nest application. It is illustrative configuration, not a complete starter:
const port = Number(process.env.PORT ?? 3000);
await app.listen(port, '0.0.0.0');
Commit a production script that starts the emitted entrypoint. Use the framework’s current Node requirement and pin the project’s supported runtime. Confirm that a fresh install and build work without global Nest tooling.
Keep schema changes out of request startup
Read DATABASE_URL inside the server-side ORM configuration. Use the driver and connection options for the chosen TypeORM, Prisma or other database library. Automatic schema synchronization is not a reviewed migration process for valuable production data.
| Release input | What to confirm |
|---|---|
| Build | Compiles the intended service and shared packages |
| Start | Runs the emitted JavaScript without the development watcher |
| Migration | Uses committed revisions and the selected database |
| Connection pool | Fits across every running process |
On Rivtor, inspect the detected root and any deploy.toml overrides. A NestJS import is a framework signal; it does not prove every application configuration is correct.
Verify routing, data and restart behaviour
Check a lightweight health route and a separate synthetic operation that inserts and reads a record. If a global route prefix is used, make the health path match the path the service really exposes. Restart the API and confirm the record persists in PostgreSQL.
When the process exits, inspect the first error rather than repeatedly retrying. A missing module needs dependency or artifact repair; a refused connection needs network and database investigation. Neither is fixed by opening private database credentials to the browser.