Setup and development

First-time setup

Make sure you have the following installed:

Installation

# Install dependencies from package.json
yarn install
1
2

Note: don't delete yarn.lock before installation, See more in yarn docsopen in new window

Database

Note: Awesome NestJS Boilerplate uses TypeORMopen in new window with Data Mapper pattern.

Configuration

Before start install PostgreSQL and fill correct configurations in .env file

DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_DATABASE=nest_boilerplate
1
2
3
4
5

Some helper script to work with database

# To create new migration file
yarn migration:create migration_name

# Truncate full database (note: it isn't deleting the database)
yarn schema:drop

# Generate migration from update of entities
yarn migration:generate migration_name
1
2
3
4
5
6
7
8

Dev server

Note: If you're on Linux and see an ENOSPC error when running the commands below, you must increase the number of available file watchersopen in new window.

# Launch the dev server
yarn start:dev

# Launch the dev server with file watcher
yarn watch:dev

# Launch the dev server and enable remote debugger with file watcher
yarn debug:dev
1
2
3
4
5
6
7
8

Generators

This project includes generators to speed up common development tasks. Commands include:

Note: Make sure you already have the nest-cli globally installed

# Install nest-cli globally
yarn global add @nestjs/cli

# Generate a new service
nest generate service users

# Generate a new class
nest g class users

1
2
3
4
5
6
7
8
9

Note: if you love generators then you can find full list of command in official Nest-cli Docsopen in new window.

Docker

if you are familiar with dockeropen in new window and docker-composeopen in new window then you can run built in docker-compose file, which will install and configure application and database for you.

Docker installation

Download docker from Official website

Docker-compose installation

Download docker from Official websiteopen in new window

Run

Open terminal and navigate to project directory and run the following command.

PORT=3000 docker-compose up
1

Note: application will run on port 3000 (http://localhost:3000open in new window)

Navigate to http://localhost:8080open in new window and connect to you database with the following configurations

host: postgres
user: postgres
pass: postgres
1
2
3

create database nest_boilerplate and your application fully is ready to use.

Last Updated:
Contributors: narek, Mohamad Jahani, Narek