Deploy a NestJS API
NestJS compiles TypeScript to dist/ at build time and runs as a Node.js process. Run your Prisma or TypeORM migrations before the release takes traffic, and the API is served over HTTPS with health checks.
Prerequisites
- A NestJS 10 or newer project (as generated by
nest new) withnest-cli.jsonand a lockfile. - The default scripts:
"build": "nest build"and"start:prod": "node dist/main". @nestjs/cliavailable at build time (it is a devDependency in generated projects).
How Deployxa detects NestJS
nest-cli.json next to package.json identifies a NestJS project on Node.js 20. Set the commands below; the generic Node.js default start command (npm start) runs nest start, which is meant for development.
Required config
// src/main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({ origin: process.env.CORS_ORIGIN?.split(',') ?? false });
app.enableShutdownHooks(); // close DB pools on redeploy
await app.listen(Number(process.env.PORT) || 3000, '0.0.0.0');
}
bootstrap();Add a cheap endpoint the health check and your monitoring can hit, for example a @Get('health') handler that returns { ok: true }, or @nestjs/terminus if you want database checks.
Environment variables
Read them with @nestjs/config (ConfigModule.forRoot({ isGlobal: true })). Variables set in Deployxa are real process environment variables, so no .env file is needed in production.
Databases and migrations
In the wizard's Configure step, set Database to PostgreSQL. The connection string is injected into the app as DATABASE_URL, so nothing needs to be committed. Choose SQLite only for small apps: it lives on a persistent volume and has no server.
Prisma
{
"scripts": {
"build": "prisma generate && nest build",
"start:prod": "prisma migrate deploy && node dist/main.js"
}
}Set the start command to npm run start:prod. Keep prisma in dependencies so the CLI exists at runtime. If migrate deploy fails the process exits, the release fails its health check, and the previous release keeps serving traffic.
TypeORM
Set migrationsRun: true with synchronize: false in the TypeORM options, or run typeorm migration:run -d dist/data-source.js before node dist/main.js.
Deploy
From the dashboard
- 1Source
Open
Dashboard → Projects → New project(/dashboard/projects/new). Pick the GitHub repository and branch, or upload a.ziparchive of the project. - 2Configure
Leave the framework preset on Auto-detect or choose Node.js API. Check the fields under advanced settings:
- Build command:
npm run build - Root directory:
./, or the sub-folder that holds the app in a monorepo - Database: PostgreSQL
- Build command:
- 3Environment
Add your variables in the table, or paste a whole
.envfile into the Bulk / .env tab. - 4Deploy
Start the deploy and watch the build log. When the release passes its health check it is served over HTTPS on its Deployxa URL.
- 5Confirm the start command and port
Open the project's Environment Canvas tab and select the web service. Set Start Command to
node dist/main.js. Set Internal Port to3000so it matches the port your app listens on. Save and redeploy if you changed anything.
From the CLI
$ npm install -g @deployxa/cli $ deployxa login $ cd my-app $ deployxa link # pick an existing project, or skip: deploy creates one $ deployxa env set JWT_SECRET "change-me" $ deployxa deploy $ deployxa logs --live # stream build and runtime logs $ deployxa open # open the live URL
If the folder is not linked, deployxa deploy creates a project named after the folder and links it (the link is saved in .deployxa/config.json). Later runs deploy the linked project. deployxa status shows the latest deployment and deployxa rollback previous returns to the release before it.
deployxa deploy packages the folder exactly as it is on disk; it does not read .gitignore. Delete local node_modules, virtualenvs, build output and real .env files first, or deploy from a clean clone. Set secrets with deployxa env set instead of shipping them in the archive.Custom domain
Go to Dashboard → Domains, choose Connect a domain you already own and pick this project. Deployxa then shows the DNS records to create at your DNS provider:
DNS changes can take several minutes to propagate; use Retry verification once they have. A Let's Encrypt certificate is issued after the domain verifies. From a linked folder you can do the same with the CLI:
$ deployxa domains add app.example.com $ deployxa dns # Waiting → Verified → SSL Active $ deployxa domains list
Common errors and fixes
Start with deployxa logs --live (or the deployment's log view in the dashboard): the build log shows dependency and compile failures, the runtime log shows crashes and bind errors. See also Troubleshooting.