Skip to content

crazyoptimist/nest-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NestJS Starter

build & test

Build a modular REST API with NestJS framework.

Table of Contents

What Is This?

This is a NestJS RESTful API starter that includes JWT authentication, OpenAPI 3 documentation, and TypeORM integration.

The reason I maintain it is because using this template allows you to quickly set up a production-ready RESTful API with minimal boilerplate code.

Getting Started

Create a dotenv file and fill it out with the appropriate values.

cp .env.example .env

Install dependencies

npm install

Run the application

npm run dev

HMR(Hot Module Reload) is configured with webpack.

Database Migrations

If you don't require incremental database migrations, set the DB_SYNC environment variable to true. This will continuously synchronize the database structure with the schema defined in the codebase.

However, DO NOT set DB_SYNC to true in a production environment, as doing so may result in data loss!

Generate a New Migration

Make sure to use npm for the following commands, as yarn does not support $npm_config_name.

npm run migration:generate --name=AddAgeColumnToUser

Migration files are located in the src/migrations directory.

Run Pending Migrations

npm run migration:run

Using Docker:

docker exec nest npm run migration:run

Revert Migrations

Revert the last migration

npm run migration:revert

Tests

# unit tests
npm run test

# e2e tests
npm run test:e2e

# test coverage
npm run test:cov

Environment Configuration

@nestjs/config has been used, so you can just inject ConfigService to read environment variables from the dotenv file.

API Documentation

OpenAPI 3.0 has been configured, and the API documentation is hosted at BASE_URL/api/docs.

Authentication

JWT authentication has been configured.

License

MIT

Maintainers

crazyoptimist