Book Image

Nest.js: A Progressive Node.js Framework

By : Greg Magolan, Patrick Housley, Adrien de Peretti, Jay Bell, David Guijarro
Book Image

Nest.js: A Progressive Node.js Framework

By: Greg Magolan, Patrick Housley, Adrien de Peretti, Jay Bell, David Guijarro

Overview of this book

Nest.js is a modern web framework built on a Node.js Express server. With the knowledge of how to use this framework, you can give your applications an organized codebase and a well-defined structure. The book begins by showing how to use Nest.js controllers, providers, modules, bootstrapping, and middleware in your applications. You’ll learn to use the authentication feature of Node.js to manage the restriction access in your application, and how to leverage the Dependency Injection pattern to speed up your application development. As you advance through the book, you'll also see how Nest.js uses TypeORM—an Object Relational Mapping (ORM) that works with several relational databases. You’ll use Nest.js microservices to extract part of your application’s business logic and execute it within a separate Nest.js context. Toward the end of the book, you’ll learn to write tests (both unit tests as well as end-to-end ones) and how to check the percentage of the code your tests cover. By the end of this book, you’ll have all the knowledge you need to build your own Nest.js applications.
Table of Contents (16 chapters)

Built-in transports

The TCP transport is only one of several transports Nest.js has built-in. Using the TCP transport, we had to bind our NestMicroservice context to an additional port, taking up yet another port on the server, and ensuring our NestMicroservice context was running before starting the NestApplication context. Other built-in transports can overcome these limitations and add additional benefits.

Redis

Redis is a simple in-memory data store that can be used as a pub-sub message broker. The Redis transport makes use of the redis NPM package and a Redis server to pass messages between the NestApplication and NestMicroservice contexts. To use the Redis transport, we need to update our bootstrap method to use the correct NestMicroservice configuration.

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    app.connectMicroservice({
        transport: Transport.REDIS,
        options: {
            url: process.env.REDIS_URL
        }
    });...