Useful Node.js Tools and Libraries

Page content

Notes on useful tools and libraries for Node.js.

Types of Application

Web Applications

Express is still most popular Web framework for Node.js, but it has been superseded by Fastify and Hapi.

Use Fastify for smaller Websites and services. Fastify can use Express plugins.

The hapi framework has a strong emphasis on quality and security, and is particularly suited for larger applications. Use it with hapi pal, which provides a command-line tool for creating and managing hapi projects.

Cloud services such as Vercel, Google App Engine, Heroku and Red Hat OpenShift provide low-maintenance hosting for Node.js Web applications.

To produce applications for function as a service infrastructure, such as AWS Lambda, use the Serverless or Claudia.js frameworks.

Websites

Eleventy is a flexible static Website generator. Gatsby relies on the React framework.

Graphical Desktop Applications

To create desktop applications, use Electron. The Electron Forge utility provides a complete set of features for developing and testing your application, including support for building installation packages.

Mobile Applications

To develop mobile applications with JavaScript, use either Ionic or React Native. Ionic creates mobile apps that use HTML, CSS and JavaScript. React Native translates JavaScript into instructions to the native APIs of each mobile operating system.

Command-line Tools

Use Commander. Add conf for configuration and Inquirer.js for prompts.

To package command-line tools, use pkg. This creates stand-alone executables that include Node.js itself, your code, and any other dependencies.

Robotics and Internet of Things

Johnny-Five is the main platform for working with robotics and hardware, such as Arduino boards.

Use the Node SerialPort packages to communicate with devices over serial connections.

Espruino provide single-chip boards and devices that are specifically designed to be programmed with JavaScript.

Development

Testing

Every JavaScript project should use ESLint.

Jest provides a comprehensive set of tools for testing. Use AVA if you would like a more lightweight test runner.

Avoid Mocha for new projects. This was a standard tool, but it has now been superseded.

  • Faker.js - Generates fake data
  • Nock - Server mocking and expectations library

Pre-commit Checks

Add Husky to your projects. It automatically runs commands before you commit code to version control. Use it with lint-staged, which applies commands to the specific files that a Git commit would change.

Build Tools

You should learn these as you need them.

By design, Node.js only includes a very minimal library of modules.

These packages offer commonly used items:

Web Clients

To connect with APIs, transfer files, and other Web tasks, use axios, a HTTP client library that has a full range of features.

If you only need a simple HTTP client, consider got, which is a lightweight interface over the Node.js HTTP client library.

You can use the HTTP client library that is included with Node.js without any third-party modules, but it uses an API that is based on callbacks, rather than promises.

In some cases, you may need to automate a Web browser. Puppeteer enables you to automate copies of Google Chrome and Chromium Web browsers.

Database Access

Knex provides a toolkit for working with SQL databases, including query building, connection handling, and schema migrations. Objection.js is an Object Relational Mapper (ORM) that builds on Knex.

Modern SQL databases support JSON documents. For example, PostgreSQL includes data types for JSON, which means that it can store and query JSON documents alongside any other data type. For most projects, a SQL database with JSON support may be more appropriate than a document database.

To access existing MongoDB services, use Mongoose. Avoid using MongoDB for new projects, because current versions of MongoDB are not Open Source.

Driver software required: To access a database service such as PostgreSQL or MongoDB, you will need to install the appropriate Node.js driver.

To work with Git repositories, use simple-git. This provides a Node.js interface for the Git command-line tool.

Common Data Types

  • date-fns - Date and time library
  • Decimal.js - A Decimal type for JavaScript
  • Format.js - String formatting for internationalization
  • Math.js - Library of standard mathematical functions
  • URI.js - Library for working with URIs, URLs and URNs
  • uuid - creates and parses UUIDs

JSON

The standard library includes support for JSON. These libraries provide additional capabilities:

  • ajv - JSON schema validator
  • flat - Flatten or unflatten objects
  • JSONata - JSON querying

Support for Other File Formats

  • Cheerio - An implementation of the jQuery API for reading and processing HTML documents with Node.js.
  • CSV for Node.js - Suite of modules for working with CSV files
  • Handlebars - Lightweight text templating
  • js-yaml - YAML
  • JSZip - ZIP archives
  • PDFKit - PDF generation
  • Remark - Markdown processor with plugin support and CLI