Node.js Ecosystem - Important Libraries and Frameworks

Node.js Ecosystem - Important Libraries and Frameworks

Here is a collection of the most common libraries and packages in the world of Node.js

1. Node.js Built-in Packages

Although Node.js has built-in modules, not all of them are useful in the real world because they are low-level that are meant for other engineers to use to build the frameworks and tools that we love and appreciate like Express.js for example. But still I'd like to highlight a couple of bult-in modules.

  1. crypto: this module allows for cryptographic functionalities like hashing passwords and generating UUIDs for databases.

  2. Path: allows to access to a certain file or folder in your server structure regardless of the operating system. This is useful when you run your application in a container in Linux while you originally built the server on Windows for example.

     const path = require('path');
     const fs = require('fs');
     const filePath = path.join(__dirname, 'filename.txt');
    
  3. fs: useful module to read from and write on your hard drive synchronously and asynchronously.

  4. gloabals: there are multiple globals (variables and objects) available for the global namespace in Node.js:

    1. process: This global object provides information and control over the Node.js process (running server). It contains properties such as process.env for environment variables, process.argv for command-line arguments, and methods like process.exit() to exit the current process.

    2. console: This global object provides methods for logging messages to the console. Common methods include console.log(), console.error(), and console.warn().

    3. require(): a global function in Node.js that is used to import modules. It's available throughout the application without needing to be explicitly declared.

    4. __filename, __dirname: the absolute path to the current file and directory respectively.

2. Express.js

Web framework to create an API. Inside one Express.js API you can build RESTful API, GraphQL, and websocket servers. It supports middlewares, error handling, routing, templating engines, and many more.

3. NestJS

Express.js is great but it lacks modularity and design patterns. The community came up with the great and amazing tool, NestJS to solve this problem. NestJS is my favourite Node.js framework and I'm highly biased to it for good reasons.

NestJS is a TypeScript-based Node.js framework for building scalable server-side applications. Inspired by Angular, it offers a modular architecture, dependency injection, and expressive decorators for defining components. Leveraging Express.js, NestJS provides seamless integration with HTTP APIs while supporting WebSocket and microservices architectures. It prioritizes developer productivity with features like guards, middleware, interceptors, and comprehensive testing support using Jest.

4. GraphQL

GraphQL is a modern query language that makes data fetching faster and more efficient than using the traditional method in RESTful APIS where we might end up in a nightmare when trying to fetch data from a databases that has a deep relationship tree. Not only RESTful URLs will break the REST standards, but also will end up over-fetching unnecessary data beyond our need. While GraphQL is a fancy word for many, but in reality, building a GraphQL server is easier than you think. There are 2 main packages available to build a GraphQL server: graphql-http and apollo-server. Personally, I use graphql-http and I don't like apollo-server.

💡
A GraphQL server can be just a part of your API and doesn't have to be your entire API.

5. Websocket

While Express.js can build HTTP servers, but HTTP is not the only communication protocol. HTTP allows the client to send requests to the server and the server responds only upon a request from the browser. But this is not the entire web. Think of your chat application. It's not built with HTTP protocol, it's built with something called websocket.

WebSocket is a communication protocol that provides full-duplex communication channels over a single TCP connection. That means that both the server and the client can send messages between each others. There are no headers like in HTTP requests, and no need to establish TCP connection for every request like in HTTP. This makes Websocket faster with low-latency.

To implement a websocket connection we have the popular package socket.io and it's very well documented.

6. JWT

JWT tokens are secure ways to authenticate requests against HTTP servers. The package used in the Node.js community is jsonwebtoken. If you'd like to learn more about authentication, you can visit my other post here: Understanding Authentication Methods: Cookies-Based vs Token-Based Authentication

7. Testing Libraries

  1. Unit Testing: Unit testing is a software testing technique where individual units or components of a software application are tested in isolation from the rest of the application. The goal of unit testing is to verify that each unit of code (e.g., functions, methods, classes) behaves as expected when given specific inputs and produces the expected outputs. A common library used here is Jest

  2. Integration Testing: individual units or components of a software application are combined and tested as a group to ensure that they work together correctly. SuperTest is an HTTP assertion library for testing web servers. It allows you to make HTTP requests to your server and assert the responses, making it ideal for testing the integration of different components in your application

  3. End-to-End Testing: Here the entire software application is tested from start to finish to ensure that it meets the requirements and behaves as expected from the user's perspective. E2E tests simulate real user interactions with the application, such as navigating through pages, interacting with forms, and submitting requests. Cypress provides a comprehensive set of tools for testing web applications, including real-time interactive testing, automatic waiting, and debugging. Cypress runs tests in the same environment as the application, allowing for fast and reliable E2E testing.

I know testing is not the favourite topic to discuss for many, but it doesn't hurt to get an introduction of it. You can check out my playlist on my YouTube channel here:

Practical Beginner Guide to Testing - Next.js | React | Jest | React Testing Library (RTL)

8. Passport.js

Passport.js is the go-to tool for anything related to authentication, from basic email/password authentication to OAuth authentication using providers like Google and Github and Twitter and all the major players.

9. Databases and ORMs

SQL and NoSQL databases like PostgreSQL and MongoDB can be implemented inside Node.js. Let's start with MongoDB.

  1. PostgreSQL is an SQL database where data is stored in tables and relationships can be established between those tables. SQL has a rigid structure, making it very robust but in the age of big data, NoSQL solutions emerged.

    To connect to a PostgreSQL database, you can use the pg package but it requires solid understanding of SQL. If you're not much familiar with SQL, you can a query builder like knex to query the database using JavaScript.

  2. MongoDB is a NoSQL database which means it doesn't provide an schema or structure to the way of saving data. Data in MongoDB is stored in documents inside collections. The collection has no structure like SQL tables, So the community came up with a library called mongoose to add error handling and other features to the MongoDB world. Mongoose creates a Model that embeds a Schema where documents follow this Schema before being stored in the collection. Each model maps to a collection inside MongoDB.

  3. ORMs: ORM simplifies database interaction in object-oriented programming languages by providing a higher-level abstraction that allows developers to work with objects rather than directly with database tables and SQL queries. It improves code maintainability and readability. But keep in mind that ORMs have performance issues and they don't suit data-driven applications where complex queries must be made. But they are great for simple interactions and they require zero knowledge in SQL.

10. Docker

At the end of the list, I want to mention deployment tools. Can we talk about deployment without mentioning Docker?

Docker is like a magic box that helps software work smoothly from start to finish. It makes sure that your programs run the same way wherever you put them, whether on your computer or in the cloud. With Docker, you can build and run your programs without worrying about different computer setups or environments. It's like having your own mini computer inside your computer, making things run faster and saving you time. Plus, it helps developers and teams work together better by making it easy to share and collaborate on projects.

I hope this list was helpful and inspiring for you! If you have any suggestions for frameworks, tools and libraries to add to the list, please make a comment below and let's make this list a resource for the developers community!

I teach all the concepts mentioned above on my YouTube channel, so if you're interested, conside subscribing to my channel here: