Skip to content

Boilerplate project to build scalable, testable and high performance Node.js microservices with gRPC.

Notifications You must be signed in to change notification settings

nlw-education/nest-service-javascript-production

Repository files navigation

Core APIs NestJS Service Template

MadeiraMadeira boilerplate project to build scalable, testable and high performance Node.js microservices.

Stack

  • NestJS: a progressive Node.js + TypeScript framework based on dependency injection;
  • gRPC: a Remote Procedure Call framework that provides high performance communication between microservices.

Features

  • REST and gRPC layers;
  • Husky Git hooks that automatically runs ESLint and Prettier before all commits;
  • ConfigService: easily manage environment variables;
  • Health module: a gRPC and a REST endpoint that displays relevant information about the application status;
  • Docker infrastructure with Docker Compose.

Installation for local development with Docker

Installation

$ cp example.env .env
$ npm install --target=12.0.0 --target_platform=linux --target_arch=x64 --target_libc=musl

Notice: these flags are needed to build the gRPC package to the correct container architecture. This issue will be fixed in the next major release of NestJS (nestjs/nest#6349).

Running the app

$ docker-compose up

Installation for local development

$ cp example.env .env
$ npm install

Running the app

# local development
$ npm run start

# local watch mode
$ npm run start:dev

# local production mode
$ npm run start:prod

Endpoints

  • gRPC: use a gRPC client (like Kreya or Insomnia) to hit http://localhost:5000/health.HealthService.GetStatus
  • REST: http://localhost:3001/health

Response

{
  "alive": true,
  "applicationName": "Core APIs Nest Service Template",
  "grpcPort": "5000",
  "restPort": "3001",
  "env": "development",
  "message": "Uncle Bob we love you"
}

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Getting started with boilerplate

Download and extract the project, then:

$ mv nest-service-template-production {your_project_name}
$ git init
$ git remote add origin https://github.com/{user}/{repo}.git

Hint: use $ git remote -v to verify new remote