Complete step-by-step instructions to set up and run the NestJS boilerplate project.
- Prerequisites
- Environment Files Overview
- Initial Setup
- Running the Project
- Database Management
- Available Scripts
- Troubleshooting
Before starting, ensure you have the following installed:
- Node.js (v18 or higher) - Download
- npm or yarn package manager
- Docker and Docker Compose - Download
- Git - Download
Verify installations:
node --version
npm --version
docker --version
docker compose versionThe project uses three environment files:
| File | Purpose | When to Use |
|---|---|---|
.env |
Local development | Running NestJS locally (outside Docker) |
.env.docker |
Docker environment | Running with Docker Compose |
.example.env |
Template file | Reference for creating new environment files |
All environment files are located in: src/environment/
git clone <repository-url>
cd <project-directory>npm install
# or
yarn install- Copy the example environment file:
cp src/environment/.example.env src/environment/.env- Edit
src/environment/.envwith your configuration:
# ===========================
# Application Configuration
# ===========================
PORT=3535
API_HOST=0.0.0.0
NODE_ENV=development
API_VERSION=1
LOG_LEVEL=debug
# Secrets
JWT_SECRET=key_name
SESSION_SECRET=key_name
PUBLIC_KEY=isPublic
# Monitoring / Error Tracking
SENTRY_DSN=https://yourPublicKey@o123456.ingest.sentry.io/1234567
# ===========================
# Database Configuration
# ===========================
DB_TYPE=postgres
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_NAME=nestjs_boilerplate_db
# ===========================
# Swagger Configuration
# ===========================
SWAGGER_URL=api-docs
SWAGGER_TITLE="NestJS Boilerplate"
SWAGGER_DESCRIPTION="A scalable NestJS boilerplate with libs, modules, TypeORM, and PostgreSQL"
SWAGGER_VERSION=1- Copy the example Docker environment file:
cp src/environment/.example.env src/environment/.env.docker- Edit
src/environment/.env.docker:
# ===========================
# PostgreSQL Configuration
# ===========================
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=nestjs_boilerplate_db
# ===========================
# pgAdmin Configuration
# ===========================
PGADMIN_PORT=5051
PGADMIN_DEFAULT_EMAIL=admin@admin.com
PGADMIN_DEFAULT_PASSWORD=postgresThis runs the NestJS app locally while using Docker for the database only.
npm run docker:up:dbThis command:
- Starts PostgreSQL container
- Starts pgAdmin container
- Uses configurations from
.env.docker
Wait about 10-15 seconds for PostgreSQL to fully start.
npm run migration:runnpm run seednpm run start:devThe application will be available at:
- API:
http://localhost:3535 - Swagger Docs:
http://localhost:3535/api-docs - pgAdmin:
http://localhost:5051
Run everything in Docker (useful for production-like environments):
# Start all services including the app
npm run docker:up:db
# In another terminal, access the app container
docker exec -it <container-name> npm run migration:run
docker exec -it <container-name> npm run seed- Open browser:
http://localhost:5051 - Login with credentials from
.env.docker:- Email:
admin@admin.com - Password:
postgres
- Email:
- Add new server:
- Host:
postgres(Docker service name) orlocalhost(local) - Port:
5432 - Username:
postgres - Password:
postgres - Database:
nestjs_boilerplate_db
- Host:
npm run migration:generate -- MigrationNamenpm run migration:runnpm run migration:revertnpm run seednpm run start:dev # Start development server with hot-reload
npm run start:debug # Start with debugging enabled
npm run build # Build the project for productionnpm run start:prod # Run production build
npm run start # Alternative production startnpm run lint # Lint and auto-fix TypeScript files
npm run format # Format code with Prettiernpm run docker:up:db # Start database services (PostgreSQL + pgAdmin)
npm run docker:down # Stop and remove all containers
npm run docker:logs # View container logsnpm run migration:generate # Generate new migration
npm run migration:run # Run pending migrations
npm run migration:revert # Revert last migration
npm run seed # Seed database with initial dataIf you see "port already in use" errors:
# Find process using the port
lsof -i :3535 # or :5432, :5051
# Kill the process
kill -9 <PID>Or change the port in your .env file.
- Ensure Docker containers are running:
docker ps- Check if PostgreSQL is ready:
docker logs <postgres-container-name>- Verify database credentials match in both
.envand.env.docker
If migrations fail:
# Stop all containers
npm run docker:down
# Remove volumes (β οΈ This deletes all data)
docker volume prune
# Restart
npm run docker:up:db
npm run migration:runClear Docker cache and rebuild:
docker system prune -a
npm run docker:up:dbsudo chown -R $USER:$USER .- Never commit
.envor.env.dockerfiles to version control - Always update
.example.envwhen adding new environment variables (without sensitive values) - Use strong secrets for
JWT_SECRETandSESSION_SECRETin production - Rotate credentials regularly in production environments
- Use environment-specific configurations for dev/staging/production
- Node.js, Docker, and Git installed
- Repository cloned
- Dependencies installed (
npm install) - Environment files configured (
.envand.env.docker) - Docker services started (
npm run docker:up:db) - Migrations run (
npm run migration:run) - Database seeded (
npm run seed) - Development server started (
npm run start:dev) - API accessible at
http://localhost:3535 - Swagger docs accessible at
http://localhost:3535/api-docs
Happy Coding! π
For issues or questions, please open an issue in the repository or contact the development team.
