NestJs
Typescript APIs with Node.js
Generators
The Nest plugin for Nx extends the generators provided by Nest. Any commands that can be used with the Nest CLI can also be used with the nx command.
tip
The --sourceRoot flag should be used for all Nest generators.
npx nx nest generate module /core/database --
Microservices
- NX
- React
- gRPC
- Kafka
- RabbitMQ
Migrations
What is the best strategy?
Validation
Automapper
yarn add @automapper/core, @automapper/classes, @automapper/nestjs class-transformer class-validator
yarn add -D @automapper/types
Architecture
Learn
- Official Nestjs Microservices
- NestJS Microservices Full Course
- Building Modern Node.JS applications with NestJS
- Supabase Nest
Testing
Deployment
- https://dev.to/kiwicopple/loading-json-into-postgres-2l28
- https://dev.to/clement/nestjs-postgresql-angular-within-nx-workspace-from-scratch-to-production-2im8
Command line
https://github.com/jmcdo29/nest-commander
Migrations
Package.json scripts
"migration:create": "npx typeorm migration:create -f ormconfig.local",
"migration:run": "ts-node --transpile-only ./node_modules/typeorm/cli.js migration:run -f ormconfig.local"
Setup and deploy
https://dev.to/clement/nestjs-postgresql-angular-within-nx-workspace-from-scratch-to-production-2im8
https://www.linkedin.com/pulse/nestjs-typeorm-migrations-nestor-iv%C3%A1n-scoles/
API Testing
Start with integration then add unit tests as needed.
- Mock data then database clean
The objectives we are trying to accomplish here are to:
Checklist | Done | Notes |
---|---|---|
test that middleware are set up (authentication, body validation) | ||
test any side effects (database operation, API calls) | ||
test the response of the HTTP request | ||
test without any mock (or hardly any mock) | ||
test each module isolated from each other | ||
test automatically as part of CD/CI |
Integration Tests
Easiest latest
- https://github.com/nxpm/nx-layouts/tree/main/nest-e2e
- https://robinck.github.io/typeorm-fixtures/
- https://gist.github.com/Ciantic/be6a8b8ca27ee15e2223f642b5e01549
- https://circleci.com/blog/getting-started-with-nestjs-and-automatic-testing/
- https://circleci.com/blog/testing-nestjs-graphql/
- https://github.com/p-salmon/nestjs-typeorm-integration-tests
Unit Tests
Once the project starts you focus on solving domain specific problems, not intfrastructur .
Job | Description |
---|---|
Stack Setup | Debugging |
Stack Setup | Test on commit |
Stack Setup | Test Service |
Stack Setup | Test Controllers |
Stack Setup | Test Integration |
Stack Setup | Map Nest to DotNet |
Context
Links
Name | Description |
---|---|
Nestjs | Official website |
Nest Patterns |