Intermediate

35 minute read

Introduction

To solve a development task, it’s better to take a step by step approach. That’s why developers create and use packages. In this article series called “Useful NPM packages for Node.js” we will periodically publish a collection of NPM packages that will give us the functionality of working with web services, time, configuration files, encryption, standardization and many more. So let’s get started.

Prerequisites

You should be familiar with JavaScript to get the most out of this article. You should also be comfortable with using the command line on your particular platform.

To install and use npm packages you need Node.js, download Node.js from the official site. If you’re running a Linux system, you can also install Node.js through your terminal, like this.

⌜ dotenv ⌝

Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More dotenv info and examples here.

⌜ config ⌝

Config organizes hierarchical configurations for your app deployments. It lets you define a set of default parameters, and extend them for different deployment environments (development, test, production, etc.). Configurations are stored in configuration files within your application, and can be overridden and extended by environment variables, command line parameters, or external sources. This gives your application a consistent configuration interface.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More config info and examples here.

⌜ nodemon ⌝

Nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More nodemon info and examples here.

⌜ winston ⌝

Winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs.  For example, one may want error logs to be stored in a persistent remote location (like a database), but all logs output to the console or a local file.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More winston info and examples here.

⌜ uuid ⌝

Create random UUID-s. Supports RFC4122 version 1, 3, 4, and 5 UUID.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More uuid info and examples here.

⌜ dayjs ⌝

Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More dayjs info and examples here.

⌜ bcrypt ⌝

A library to help you hash passwords.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More bcrypt info and examples here.

⌜ node-cron ⌝

The node-cron module is tiny task scheduler in pure JavaScript for node.js based on GNU crontab. This module allows you to schedule task in node.js using full crontab syntax.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More node-cron info and examples here.

⌜ jsonwebtoken ⌝

An implementation of JSON Web Tokens. JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More jsonwebtoken info and examples here.

⌜ express ⌝

Fast, unopinionated, minimalist web framework for node. Robust routing. Focus on high performance. Super-high test coverage. HTTP helpers (redirection, caching, etc). View system supporting 14+ template engines. Content negotiation. Executable for generating applications quickly.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More express info and examples here.

⌜ passport ⌝

Passport’s sole purpose is to authenticate requests, which it does through an extensible set of plugins known as strategies. Passport does not mount routes or assume any particular database schema, which maximizes flexibility and allows application-level decisions to be made by the developer. The API is simple: you provide Passport a request to authenticate, and Passport provides hooks for controlling what occurs when authentication succeeds or fails.

Passport uses the concept of strategies to authenticate requests. Strategies can range from verifying username and password credentials, delegated authentication using OAuth (for example, via Facebook or Twitter), or federated authentication using OpenID. Before authenticating requests, the strategy (or strategies) used by an application must be configured.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard

Testing:

Copy to Clipboard
More passport info and examples here.

⌜ json-server ⌝

Get a full fake REST API with zero coding. Created for front-end developers who need a quick back-end for prototyping and mocking.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More json-server info and examples here.

⌜ swagger-ui-express ⌝

This module allows you to serve auto-generated swagger-ui generated API docs from express, based on a swagger.json file. The result is living documentation for your API hosted from your API server via a route.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More swagger-ui-express info and examples here.

⌜ helmet⌝

Helmet helps you secure your Express apps by setting various HTTP headers. It’s not a silver bullet, but it can help!

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More helmet info and examples here.

⌜ express-handlebars⌝

A Handlebars view engine for Express which doesn’t suck.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More express-handlebars info and examples here.

⌜ React CLI

React is a JavaScript library for building user interfaces. Create React apps with no build configuration.

Installation and Usage (npm) :

Copy to Clipboard
More React CLI info and examples here.

⌜ Vue CLI

The Progressive JavaScript Framework. Standard Tooling for Vue.js Development.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More Vue CLI info and examples here.

⌜ Angular CLI

The modern web developer’s platform. The Angular CLI is a command-line interface tool that you use to initialize, develop, scaffold, and maintain Angular applications directly from a command shell.

Installation (npm) :

Copy to Clipboard

Usage:

Copy to Clipboard
More Angular CLI info and examples here.

⌜ PM2 ⌝

ADVANCED, PRODUCTION PROCESS MANAGER FOR NODE.JS. PM2 is a daemon process manager that will help you manage and keep your application online 24/7

Installation (npm) :

Copy to Clipboard

Usage :

Copy to Clipboard
More PM2 info and examples here.

Conclusion

The packages we explored, can be used as an starting point for your next project. If you are considering learning how to use Node.js NPM packages, you should start by learning the Node.js language first. This will give a significant competitive advantage in the job market. Looking forward to next packages collection article. Thank you for reading!