What Is NestJS?
NestJS is a progressive Node.js framework for building efficient, scalable server-side applications. It uses TypeScript by default and follows a modular architecture inspired by Angular. Deploying NestJS on your Breeze provides a robust foundation for enterprise-grade APIs.
Prerequisites
- A Breeze running Ubuntu 22.04 or later
- Node.js 18+ installed
- Nginx installed
Step 1: Install and Create a Project
sudo npm install -g @nestjs/cli
nest new my-api
cd my-apiStep 2: Build for Production
npm run buildThis compiles TypeScript to JavaScript in the dist/ folder.
Step 3: Create a Systemd Service
sudo nano /etc/systemd/system/nestjs.service[Unit]
Description=NestJS API
After=network.target
[Service]
User=www-data
WorkingDirectory=/var/www/my-api
ExecStart=/usr/bin/node dist/main.js
Restart=always
Environment=NODE_ENV=production
Environment=PORT=3000
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable --now nestjsStep 4: Nginx Reverse Proxy
server {
listen 80;
server_name api.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}sudo ln -s /etc/nginx/sites-available/nestjs /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d api.yourdomain.comAdding Modules
Generate resources quickly: nest g resource users creates a controller, service, module, and DTOs. NestJS supports TypeORM, Prisma, and Mongoose for database integration.