Help Center

NodeJS + NestJS + PostgreSQL

NestJS is a Node.js framework for building server-side applications with a defined architecture: modules, controllers and providers with dependency injection. It’s written in TypeScript and is the usual choice when a Node project needs a structure that scales with the team.

This Stack combines it with PostgreSQL.

Services included

In addition to your application, the Stack starts PostgreSQL, an nginx that receives traffic on port 80, an automatic backups service, and the web file manager.

Project structure

text
.
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ src
β”‚   β”‚   β”œβ”€β”€ app.controller.ts
β”‚   β”‚   β”œβ”€β”€ app.module.ts
β”‚   β”‚   β”œβ”€β”€ database.service.ts
β”‚   β”‚   └── main.ts
β”‚   β”œβ”€β”€ package.json
β”‚   └── tsconfig.json
β”œβ”€β”€ backup
β”‚   └── backup-runner.sh
β”œβ”€β”€ nginx
β”‚   └── default.conf
β”œβ”€β”€ .env.example
β”œβ”€β”€ app.Dockerfile
└── compose.yaml

Getting started

Install the Stack and bring it up:

bash
docker-deploy-stack --stack javascript/nestjs-postgres
cd /root/stack/javascript/nestjs-postgres
docker compose up -d

Then replace the example application with yours, via Git, by SFTP or from the web file manager, following como-despliego-una-aplicacion-en-un-stack.md. Your code goes in the app/ folder.

Each time you update the code, apply the changes:

bash
docker compose up -d --build

Configuration

Editable values are in the Stack’s .env file:

Variable Default Purpose
APP_PORT 80 Public port of the Stack.
APP_ENV development Application environment.
DB_NAME nestjs Database name.
DB_USER nestjs Database user.
BACKUP_ENABLED 1 Automatic backups: 1 enabled, 0 disabled.
BACKUP_INTERVAL_SECONDS 86400 How many seconds between backups.
BACKUP_RETENTION_DAYS 7 How many days backups are retained.
POSTGRES_VERSION 16-alpine Version of the corresponding image.

After changing it, apply the changes with docker compose up -d.

Useful commands

bash
docker compose ps          # see running containers
docker compose logs -f     # view live logs
docker compose restart     # restart services
docker compose down        # stop and remove containers
Guide g.0293 Β· Source version 1 Β· en