Quick Start: Hello World
You can deploy a minimal NestJS app to test the workflow.- Create a new NestJS project locally:
- Modify src/app.controller.ts (or similar) to return a simple message:
- Test locally:
Overview
NestJS is a progressive, extensible framework for building efficient, scalable server-side applications in Node.js. It uses TypeScript by default and supports modular architecture, dependency injection, and multiple transport layers. On DCDeploy, you can deploy NestJS applications using:- Build-from-code (auto-detecting Node.js projects)
- Dockerfile — for custom control over build, runtime, and dependencies
Prerequisites
- A NestJS project (with TypeScript)
- package.json must have correct scripts like start, build, etc.
- A GitHub (or Git) repo containing your project
- If using Docker, a Dockerfile in project root
- Knowledge of environment variables for DB credentials, etc.
Step-by-Step Guide
- Prepare Your NestJS App
- Ensure the app listens on 0.0.0.0 on process.env.PORT || 3000.
- Replace any hardcoded DB credentials / secrets with environment variables.
- (Optional) Dockerfile
Here’s a sample
Dockerfile:
- Push Code to Git Commit your code, tag your branch (e.g. main). Ensure .dockerignore excludes node_modules, dist, etc.
- Deploy on DCDeploy
- In DCDeploy dashboard → Navigate to the environment → Deploy tab
- Add a new service → Choose Build from Code (or Docker if using custom image).
- Provide repo URL, branch/ref.
- Set port 3000, ensure listening address 0.0.0.0.
- Choose protocol (HTTP/HTTPS), region(s).
- Configure environment variables needed (e.g. DB_HOST, DB_USER, DB_PASS, DB_NAME).
- Select machine type (CPU, RAM) based on expected load.
- Set minScale/maxScale as needed.
- Deploy and monitor logs & revision events.
Example Service Config
Best Practices
- Use internal networking for connecting to databases or services within DCDeploy.
- Add a health check endpoint (e.g., /healthz) for better deployment monitoring.
- Set NODE_ENV=production for performance optimizations.
- Keep the Docker image small (use Alpine or slim images, multi-stage builds).
- Use logging, and avoid exposing secrets in code.
- Use SSL / custom domain for secure access in production.
Troubleshooting
| Problem | Likely Cause | Solution |
|---|---|---|
| App not accessible after deployment | App isn’t listening on 0.0.0.0 or wrong port configured | Check listening address & port in both NestJS code & DCDeploy service config. |
| Build fails due to missing TypeScript compile | Missing build script or dependencies | Ensure npm run build works locally; include tsconfig, etc. |
| Environment variables not set or wrong | Variables missing in DCDeploy dashboard | Add required env vars accurately. |
| Slow cold start or high memory usage | Large dependencies, SSR, or unoptimized build | Use slim base images, optimize dependencies, increase memory if needed. |
