Skip to content

An example NestJS project that uses TypeORM to demonstrate a Node.js-based REST microservice.

License

Notifications You must be signed in to change notification settings

christophersmith/nestjs-rest-orm-user-microservice

Repository files navigation

NestJS + TypeORM + Swagger REST User Microservice

An example NestJS project that uses TypeORM to demonstrate a Node.js-based REST microservice. This example compliments my Lab Notes: Looking at NestJS for Web Apps – Overview, Performance, Thoughts blog article where I provide an overview of NestJS, discuss performance, and wrap up with thoughts from a developer perspective.

This application uses TypeORM and Swagger to implement a simple REST microservice using the default NestJS configuration. The REST endpoints allow you to retrieve and manage user records from a Microsoft SQL Server database. You are able to get a list of all users, get one user, create a user, update a user, and delete a user. All client input, like user identifiers or details, is validated.

Requirements

Installation

The following commands should be run from the project directory after you've installed the requirements above.

Install the required node packages and build the project:

$ npm install
$ npm run build

Start up the Docker container with Microsoft SQL Server:

$ docker-compose up

Once the Docker container is started, run the following command to create the necessary database tables:

$ npm run typeorm:migration:run

OPTIONAL: Run this command if you'd like some dummy data to play with:

$ npm run seed:run

Running the app

To run the application, execute the command:

$ npm run start

Once started, you can acess the Swagger API from http://localhost:3000 to experiment with the API calls.

When finished, you can stop the NestJS app and the docker-compose process by pressing the keys CTRL + C.

Test

The following commands will run tests. Please note that the database should be running (via docker-compose up) for the end-to-end tests.

# unit tests
$ npm run test

# end-to-end tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

About

An example NestJS project that uses TypeORM to demonstrate a Node.js-based REST microservice.

Topics

Resources

License

Stars

Watchers

Forks