Create NestJS health check library

Loading

Reading Time: 6 minutes Introduction NestJS applications in my company implement health checking for k8s liveness probe. These applications check the following items are up and running: backend, database, redis, bull queue and external servers. Eventually, different backend teams encapsulate similar endpoint and services in a heath check module and import it to the application. This approach is not … Read more

Check health of nestjs bull queue with terminus

Loading

Reading Time: 5 minutes Introduction It is common for enterprise applications to connect to external resources to process requests and get back responses. Therefore, application should know that the components it depends on are up and running all the times. Otherwise, the application behaves erroneously when serving client requests. To stay aware of the availability of connected resources, we … Read more

Queue and job processing in nestjs

Loading

Reading Time: 5 minutes Introduction The responsibility of backend application is to handle client requests and return responses back to the client. However, backend performance can degrade when the request is resource intensive; UI thread waits endlessly and user interface is blocked for further user actions. To avoid the unresponsiveness, we can place jobs in queue and delegate the … Read more

Lint files and dependencies in NestJs with unimported

Loading

Reading Time: 5 minutes Introduction When developers maintain a NestJS project, they add and delete codes to the project that some dependencies and files become redundant. When unused files and dependencies are left around, they become technical debts and reduce the code quality. Fortunately, we can use unimported to lint files and dependencies before git commit to avoid pushing … Read more

Create dynamic module made easy in NestJS 9

Loading

Reading Time: 4 minutes Introduction Our technology team builds a lot of Nestjs libraries to reuse in Nestjs applications. Our libraries provide forRoot() to create dynamic module only. Therefore, we cannot call forRootAsync() to register asynchronous module by importing modules and injecting services. Before V9, there are many boilerplate codes to get forRootAsync() to work. Internally, forRootAsync invokes createAsyncProvider … Read more

Author nestjs library using Angular Schematics

Loading

Reading Time: 7 minutes Introduction When I create nestjs project to do proof of concept, I usually spend the first hour to install dependencies and add rules to eslintrc.js before writing any meaningful code. When I researched code generation in nestjs, I found out that angular schematics can author nestjs library to upgrade configurations and add new files. Therefore, … Read more

Swagger In NestJS

Loading

Reading Time: 5 minutes Problem: Frontend developers complained that integration with API is a painful process because there is no documentation on available endpoints, expected payloads and responses. Therefore, our backend team leads elect to enable swagger such that frontend developers can browse all the APIs on dedicated documentation site. When they showed me how it was done, I … Read more

Dynamic Task Scheduler In NestJS

Loading

Reading Time: 7 minutes Scenario: Our ESG (Environmental, Social, and Governance) platform requires to run schedule jobs to call endpoints to generate reports for internal teams and send company emails to our customers. Development team was tasked with developing a job scheduler that executes cron jobs at a specified period of time. node-cron is a popular open source library … Read more

Stripe Integration In NestJS

Loading

Reading Time: 6 minutes Scenario: Our ESG (Environmental, Social, and Governance) platform offers monthly and annual subscriptions to charge customers for using our ESG reporting service. When we designed our payment module, we chose Stripe as our payment platform because it accepts credit card payment method, provides good documentations and open source node library for the API (stripe-node). Problem: … Read more

How I cache data list in memory using useFactory in NestJS

Loading

Reading Time: 3 minutes Scenario: Application at work stores data lists in database tables and they never change after initial population. These data lists are used for dropdown selection in frontend, for example, users select their salutation in user profile page and click to make the change. Problem: When user opens the page, UI makes a HTTP request to … Read more