Notes on useful tools and libraries for Node.js.
Types of Application
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.
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.
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
Use the Node SerialPort packages to communicate with devices over serial connections.
Avoid Mocha for new projects. This was a standard tool, but it has now been superseded.
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.
You should learn these as you need them.
- dotenv - Loads environment variables from files
- rimraf - Cross-platform file deletion
- semantic-release - Automates the package release workflow
- Swagger - OpenAPI code generation for clients and servers
- Webpack - Web assets compiler
By design, Node.js only includes a very minimal library of modules.
These packages offer commonly used items:
- Chokidar - User-friendly filesystem watcher
- Nodemailer - Sending emails
- Passport - Authentication
- Winston - Logging
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.
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
- 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
The standard library includes support for JSON. These libraries provide additional capabilities:
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