Juan Camilo Peña Vahos
Developer in Cidenet S.A.S.
The title of this article may seem confusing, due to Spring Boot is a framework for developing backend applications in Java, while NodeJS is a Runtime Environment (RTE). In the Java environment, the equivalent to Node is the JRE.
So why the title? Because the Node community has developed a set of libraries, enriched day by day, to develop robust backend applications, and together they form a parallel to Spring Boot that is not centralized in a single company or group of developers. Many of them are even open-source, and this means that we can collaborate to improve them.
Most of the projects in Cidenet have been carried out with Spring Boot, and it is clear that this robust framework seems to have dependencies for any need the application has; Call it logger, environment variable manager or error manager, among others.
With this short article, I want to show you some of the dependencies that have become popular to solve these same needs in a backend application developed with NodeJS. I will leave express aside because the objective is not to show how to make a backend application with this framework, but what dependencies to add to it.
Note: I will leave the links in npm, but if you use yarn or some other package manager, you will find them too.
Bcrypt is quite popular, easy to use by the developer, but quite complicated in its depth. Using even Python resources, this dependency will be in charge of encrypting data in a single direction. It is very popular for encrypting user keys and other sensitive data. In fact, Spring Security uses this same algorithm internally.
See more about Bcrypt
Do you need to send an email? Nodemailer is the manager of the most popular mail service in NodeJS.
It is common for a backend application to send emails to notify events. Nodemailer is the most used library for this work in NodeJS. Its functions include being able to configure an HTML format for the body of the email, using protocols other than SMTP (what is known as “transport methods”); You can even send encoded images through some plugins.
See more about Nodemailer
In Spring we use log4js as a library to generate logs.
Logs are event records that we can consult later. The most common is to use them to record the traces of errors captured by the application. Winston is the most used Logger in NodeJS. Its functionalities are extensive, allowing you to manipulate files in different formats, control multiple files, and define different levels of logging (info, error, alert, etc). Winston also has functions to facilitate the work of automatic log analyzers.
See more about Winston
In Spring Boot we have the properties file where we keep variables that are used throughout the entire application or environment variables. Environment variables are very important because they define the environment in which you are working. The variables will have different values depending on the stage in which the project, can be production, development, QA, or any other that the company implements.
DotEnv is a dependency that allows us to manipulate and load, in the application, environment variables stored in .env file. Not only that, but it also offers functions to be able to select between multiple environment files, which will allow us to define a logic to change between them, depending on the state of the project.
See more about DotEnv
Underscore is a JS library that extends this set of functions.
It is very useful for handling objects and arrangements and you will save a lot of time in operations such as filtering and mapping them.
See more about Underscore
E2E testing requires making requests to the API you are designing. Supertest is a library that allows you to make a fake response so that we can test the behavior of the endpoints we have created.
There are more important functions in any API in the areas of security, authentication, authorization, and error handling, among others. We can mention here JWT or Passport (which is the most used in terms of authentication).
The objective of this article is to inform about the existence of these tools. When it starts working with Node, coming from a context like Spring’s, you may think that you must fight yourself to solve these problems when the reality is that the majority are already ready to be used quickly.
The invitation is to make a small consultation before each development, it is possible that existing tools that do it or help to facilitate it.