/nest-rest-api

Template Repo for a NestJS REST API

Primary LanguageTypeScript

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Template REST API built using NestJS.

Features:

  • Authentication using JWTs & UseGuards (Register, Login)
  • Email Integration (Registration Confirmation, Forgot Password)
  • Scaffold CRUD (User, Widget)

Installation

Before you can start the application you have to create an .env file by running

$ cp template.env .env

Then update all of the variables in your local version of .env. This file is not committed to Git because it contains private keys you don't want exposed publicly.

This application is dockerized, so to start it just run:

docker-compose up -d

## Run migrations
docker-compose exec api npm run typeorm:migration:run

Development

Generating New Migrations From New Entities

This application uses TypeORM to interact with the Database. We can automatically generate new migrations based on the state of our entity files by following these instructions:

  1. First create a new entity, and related resources, using the nest CLI, npx nest g new resource resourceName
  2. Update the Entity file based on your ERD
  3. Compile the application with npm run build. We need our Entity fils in JS because TypeORM can't read TypeScript files
  4. Run the generate migration common, npm run typeorm:migration:generate -- migrationName

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov