Home

Published

- 3 min read

Service with nestjs and airtable

img of Service with nestjs and airtable

When working in Node.js we have a variety of options to create a framework to help us generate resource availability, for example: express.js, loopback, nest.js and others.

Particularly, I like Nestjs because I have worked in Angular and I know its benefits: Use of TypeScript, defined architecture, defined tools.

At the moment also, I am deepening in the use of tools and backend development, to extend my knowledge and experience and offer better services at a professional level.

I was curious about how I can integrate services with Nestjs and if it was possible to implement this in a decoupled way to the framework. Use cases that help me to doubt and look for answers:

Unit tests: how can I test my application if I use different services and their implementations are different, would my tests be easy to write, would they make sense?

What if the integration to these services change? should I change the implementation in my framework and my tests? would the configurations or endpoints I expose break?

Based on this, I set to work and got answers:

  1. The key: The framework services, whenever we think about unit tests we must analyze the way we implement what we are going to test: The more difficult tests are to write the more noise they generate, that is, the more likely we are doing something wrong. Therefore, is it possible to do the integration to an external service of my API in another place? The answer is yes, for example: The external service in this case: Airtable
  2. Changes in the implementation of external services: How do they affect my macro? do they break configurations and exposed resources? if this is a doubt we have the best thing to do is to implement the Adapter Design Pattern which is nothing more than a file that mutates the structure of the data coming from the external service and that returns that data to the framework service and that will handle the possible corner cases (if something changes from the external service, we will update only this file, the rest of the framework will not know). In this case, we could handle this adapter in the same service that we implemented here, however, at the moment we don’t have it: I invite you to make a PR with a proposal.

You can see the unit tests here

These conclusions give me to understand that yes, personally and for the moment Nestjs would be my favorite tool to make backend, because I can make integrations with external services very easily maintaining a good infrastructure of the project and without coupling to such services, in addition to its similarity to Angular (that I personally know) and the benefits that this brings.

Related Posts

There are no related posts yet. 😢