Lesson 26 / 34

Deployment

Build, configure and run a NestJS app in production with NODE_ENV, a process manager and health-check endpoints.

Build for production

Compile TypeScript to JavaScript with the Nest build; the output goes to dist/. Install only production dependencies in the final image.

npm run build
ls dist/  # compiled JS output

Run in production

Set NODE_ENV=production and run the compiled dist/main.js; optionally use a process manager such as PM2.

NODE_ENV=production node dist/main.js

# or with PM2
pm2 start dist/main.js --name "nestjs-app"

Health check endpoint

Add a /health or /ping endpoint for load balancers and orchestrators to poll.