Alen IBRIC
5 min readMar 17, 2020

10 Useful Modules for Node.JS

Node.js offers many modules that make it easy for developers to work on a daily basis. Some may be well-known, some less well-known, but the fact is that many of them will be in need of every developer at some point. Find out in time what the modules are and how they can be used.

Node.js has gained popularity over the years, and is now often used to develop server side web applications, or at all during programming. The npm homepage currently has nearly half a million free modules, which is the world’s largest repository of its kind.

Below, find out what node.js modules are currently popular and what kinds of programming work can make it easier. These include software development, data validation, string generation, PDF generation, and many more.

DATE FORMAT

The standard JavaScript API already has the ability to work with dates and times. But this item is not that useful when it comes to printing and formatting dates. Because of that, moment.js offers a simple API that makes it easy to read and understand.

The functionality of splitting and formatting dates in different time zones is additionally useful.

IMAGE PROCESSING

GraphicsMagick and ImageMagick are two popular image creation and editing tools. With node.js, both can be used directly from JavaScript, and it supports the most common image editing operations: resizing, clipping, and encoding.

SENDING EMAILS

Programmatic emailing is a feature often used on websites. From validating user registration to notifying users and sending newsletters and promotional offers, there are a variety of reasons to get in touch with users.

The standard node.js API does not offer such functionality, so the Nodemailer module was created, which supports both text content, HTML content, and image embedding, all using the provided SSL / STARTTLS protocols.

WORKING WITH COLORS

While there may be developers who have never worked with colors, the fact is that this will happen once in a while. The module that helps is TinyColour2, and is available for node.js and browsers.

It has sets of methods like toHexString () and toRGBString (), but also methods for different types of color operations, such as lighten (), saturate (), and complement ().

DATA VALIDATION

When forms are available on the site, the information entered by the user should be verified. This should be done by both the client (browser) and the server — to prevent incorrect data.

The module that helps is validator.js, as it offers multiple ways to validate data. These include isEmail (), isURL (), isMobilePhone () or isCreditCard (). An added benefit of this module is that it works for both servers and clients.

REST API MANAGEMENT

When it comes to web applications that use a variety of services, REST is the undisputed standard. Express allows you to create such services, but it often comes bundled with templates and the creation of often unnecessary products.

However, the restify module helps in making the REST API and debugging it. It is similar to Connect, but provides greater control over HTTP interactions and supports DTrace, which helps in timely solving application problems.

REDUCING HTML

HTML reduction is just one of the options, because in addition to HTML, images, CSS, JavaScript, SVG can also be reduced.

The HTMLMinifier module can be used at the command line, but is available behind gulp and Grunt. There are also intermediate solutions that can be embedded in Koa and Express, and HTML can be minimized directly on startup, before being delivered to the client via HTTP.

From what appears on the homepage of this module, it is currently the best HTML renderer.

CREATE FILES IN FORMAT PDF

Dynamic PDF creation is made possible by the PDFKit module, which supports the inclusion of font types, images, and vector graphics definitions.

You can additionally define links, include notes, highlight text, etc. For those who are intrigued, we recommend additional literature — demos.

MAKING FAKE DATA

User interface testing involves dealing with a lot of false information, such as email addresses, usernames, addresses, and phone numbers, and in such cases it is useful to know the faker.js module.

It can be used on the server (as a node.js module), or on the client side, and provides a set of methods for generating false data. Simply calling the faker.internet.userName () command gives a random username, and calling the faker.company.companyName () command gives the name of a nonexistent company.

MAKING CLI APPLICATIONS

There are already a handful of CLI applications that handle various issues through node.js. However, the commander.js module is useful for manually writing CLI applications, as it provides an API for defining various aspects of CLI applications such as commands, options, names, help, and more. This greatly simplifies the process of creating command line applications.

CONCLUSION

The popularity of the JavaScript programming language not only does not decline, but is growing daily. As a result, more and more libraries are emerging and their modules provide a wealth of functionality.

Modules like the ones for working with dates, image processing, colors, data validation, creating fake data, sending emails, minimizing HTML are just some of the extremely useful node.js modules we encounter on a daily basis.

Originally published at https://www.alenibric.com.tr

Alen IBRIC
Alen IBRIC

No responses yet