nest.js_Nest.js入门

nest.js

If you have ever worked on a Node.js application before, either built a REST API or an enterprise application, you must have realised how tedious and daunting it was to maintain, especially whenever the application start to scale. The more you add new features to the application, the larger the codebase.

如果您以前曾开发过REST API或企业级应用程序而曾在Node.js应用程序上工作过,那么您一定已经意识到它的维护难度和艰巨性,尤其是在应用程序开始扩展时。 您向应用程序添加新功能的次数越多,代码库就越大。

Creating a proper structure for such application can result into serious headache if not properly managed, especially as a result of application specific configurations. This is why Nest.js was created.

如果管理不当,尤其是由于应用程序特定的配置,为此类应用程序创建适当的结构可能会导致严重的头痛。 这就是创建Nest.js的原因。

Nest.js was built mainly to eliminate disorganized codebases and give Node.js application a moderate and reasonable structure out of the box. Heavily inspired by Angular, Nest.js was built with TypeScript and uses Express.js under hood. This rightly makes it compatible with the majority of express middleware.

Nest.js的构建主要是为了消除混乱的代码库,并为Node.js应用程序提供适度而合理的结构。 Nest.jsAngular的大力启发,是使用TypeScript构建的,并在后台使用Express.js 。 正确地使其与大多数表达中间件兼容。

In this post, I will introduce and take you through the process of getting started with Nest.js. You will learn about several ways to install the framework on your machine and why you need to consider using it for your next project. In the process of doing this, you will create a very simple RESTful API that enables users to fetch, create and delete books in a bookstore.

在本文中,我将介绍并带领您完成Nest.js的入门过程。 您将了解在计算机上安装框架的几种方法,以及为什么需要考虑将其用于下一个项目。 在执行此操作的过程中,您将创建一个非常简单的RESTful API,使用户能够在书店中获取,创建和删除书。

This is a very simple application but yet broad enough to give you comprehensive insight on how to craft an application with Nest.js.

这是一个非常简单的应用程序,但又足够广泛,可以使您全面了解如何使用Nest.js编写应用程序。

先决条件 ( Prerequisites )

Familiarity with TypeScript and a reasonable knowledge of JavaScript will help you get the best out of this tutorial. Experienced with building applications with Angular will be a plus but not a requirement as the article will give you a proper guide on how to easily begin.

熟悉TypeScript并具有一定JavaScript知识将帮助您充分利用本教程。 具有使用Angular构建应用程序的经验将是一个加分,但不是必需的,因为本文将为您提供有关如何轻松开始的正确指南。

You need to install Node and npm. It is advisable to also install nodemon globally on your machine.

您需要安装Node和npm。 建议在您的计算机上全局安装nodemon

Nest.js概述以及使用原因 ( Overview of Nest.js and why use it )

Nest.js is a server-side Node.js framework for building efficient, reliable and scalable applications. Built by Kamil and backed by quite a number of reputable organizations and individuals.

Nest.js是服务器端Node.js框架,用于构建高效,可靠和可扩展的应用程序。 由卡米尔(Kamil)建立,并得到众多知名组织和个人的支持。

Nest.js was introduced to solve the architectural problem of Node.js by giving backend applications a modular structure for organising code into separate modules.

引入Nest.js是为了通过为后端应用程序提供用于将代码组织到单独的模块中的模块化结构来解决Node.js的体系结构问题。

Fully built with TypeScript, it comes with the benefits of code type checking and dependency injection which helps to facilitate the process of development of applications. If you are conversant with the structure of Angular applications, you are going to feel so comfortable with the key concepts of Nest.js and getting started with it will be quite an easy task. Anyways, this post will provide you with the required details needed to start building applications with Nest.js.

它完全使用TypeScript构建,具有代码类型检查和依赖项注入的优点,这有助于简化应用程序的开发过程。 如果您熟悉Angular应用程序的结构,那么您将对Nest.js的关键概念感到非常满意,并且开始使用它将是一件容易的事。 无论如何,本文将为您提供开始使用Nest.js构建应用程序所需的详细信息。

In addition, the following list shows some of the benefits of Nest.js as explained here by Kamil:

此外,以下列表显示了Kamil 在此说明的Nest.js的一些优点:

  • it surrounds your route handler body with try..catch blocks

    它用try..catch块围绕您的路由处理程序主体

  • it makes every route handler async

    它使每个路由处理程序都async

  • it creates a global express router

    它创建了一个全球快递路由器

  • it creates a separated router for each controller

    它为每个控制器创建一个单独的路由器

  • it binds error-handling middleware

    它绑定了错误处理中间件

  • it binds body-parser middleware (both json and extended urlencoded)

    它绑定了body-parser中间件( json和扩展的urlencoded

Now that you have been briefed about this awesome framework, let’s take a look at the building blocks of Nest.js.

现在,您已经了解了这个很棒的框架,让我们看一下Nest.js的构建块。

Nest.js的构建块 ( Building blocks of Nest.js )

The following are the building blocks used when building Nest.js applications:

以下是构建Nest.js应用程序时使用的构建块:

控制器 (Controllers)

Typical to most web frameworks, controllers in Nest.js are responsible for handling any incoming requests and returning responses to the client side of the application. For example, if you make an API call to a particular endpoint, say /home, the controller will receive this request and based on the available resources, it will returned the appropriate response.

Nest.js中的控制器是大多数Web框架的典型代表,负责处理所有传入请求并将响应返回到应用程序的客户端。 例如,如果您对特定端点(例如/home进行API调用,则控制器将接收到该请求,并基于可用资源,它将返回适当的响应。

Nest.js was structured in a way that the routing mechanism is able to control which controller will be responsible for handling a particular request.

Nest.js的构建方式使路由机制能够控制哪个控制器将负责处理特定请求。

Defining a basic controller in Nest.js is as good as creating a TypeScript file and including a decorator @Controller() just like the code snippet below:

在Nest.js中定义基本控制器与创建TypeScript文件并包括装饰器@Controller()一样好,就像下面的代码片段一样:

// users.controller.ts 

import { Controller, Get } from '@nestjs/common';

@Controller('users')
export class UsersController {
 @Get()
 findAll() { 
   return 'This will return all the users';
 }
}

The prefix of users within the Controller decorator will prompt the UsersController to handle any /users GET request within an application and return the appropriate response as specified. Other HTTP request handled by the controller includes POST , PUT, DELETE as we will see later in the tutorial.

Controller装饰器中users的前缀将提示UsersController处理应用程序中的任何/users GET请求并返回指定的适当响应。 控制器处理的其他HTTP请求包括POSTPUTDELETE ,我们将在本教程的后面部分看到。

Once a controller is created, it needs to be added to the module definition before Nest.js can easily recognise it. This could be the root ApplicationModule or any other module created within the application. More about this in the module section of this post.

创建控制器后,需要将其添加到模块定义中,Nest.js才能轻松识别它。 这可以是根ApplicationModule或在应用程序内创建的任何其他模块。 有关更多信息,请参见本文的模块部分。

提供者 ( Providers )

As mentioned earlier, Nest.js was heavily inspired by Angular and similar to an Angular application, one can easily create a provider and inject it into controllers or other providers too as well. These providers are also called services and based on the philosophy of Nest.js, it was designed to abstract any form of complexity and logic to a class called service.

如前所述,Nest.js受到Angular的极大启发,并且与Angular应用程序类似,因此可以轻松创建提供程序并将其注入到控制器或其他提供程序中。 这些提供程序也称为服务,并且基于Nest.js的原理,旨在将任何形式的复杂性和逻辑抽象到称为服务的类中。

A service provider in Nest.js is just a normal JavaScript class with a special @Injectable() decorator at the top.

Nest.js中的服务提供者只是普通JavaScript类,顶部带有特殊的@Injectable()装饰器。

For example, you can simply create a service to fetch users as shown below:

例如,您可以简单地创建一个服务来获取用户,如下所示:

// users.service.ts

import { Injectable } from '@nestjs/common';
import { User } from './interfaces/user.interface';

@Injectable()
export class UsersService {
  private readonly users: User[] = [];

  create(user: User) { 
    this.users.push(user);   }

  findAll(): User[] {
    return this.users;
  }
}

The provider created above is a class with two methods create() and findAll(), which can be used to create and return all users respectively. And to easily help with type checking an interface was used to specify the type of elements that should be received by the methods.

上面创建的提供程序是带有两个方法create()findAll() ,可分别用于创建和返回所有用户。 为了方便进行类型检查,使用了一个接口来指定方法应接收的元素的类型。

模组 ( Modules )

Modules are more like the most important basic building block in Nest.js. They are TypeScript files decorated with @Module decorator. This attached decorator provides metadata that Nest makes use of to organize the application structure. With modules you can easily group related files into one.

模块更像是Nest.js中最重要的基本构建块。 它们是用@Module装饰器装饰的TypeScript文件。 该附加的装饰器提供元数据,Nest可以利用元数据来组织应用程序结构。 使用模块,您可以轻松地将相关文件分组为一个。

Each Nest.js application must have at least one module, usually referred to as the root module. This root module is the top-level module and usually enough for a small application but it is advisable to break a large application into multiple modules as it helps to maintain the structure of the application.

每个Nest.js应用程序必须至少具有一个模块,通常称为root模块 。 该根模块是顶级模块,通常对于小型应用程序就足够了,但是建议将大型应用程序分解为多个模块,因为它有助于维护应用程序的结构。

If you have an application that manages a lot of data or functionality about users , we can group both the controller, services and other related files into a single module, say UsersModule for example:

如果您有一个管理有关用户的大量数据或功能的应用程序,我们可以将控制器,服务和其他相关文件都分组到一个模块中,例如说UsersModule

import { Module } from '@nestjs/common';
import { UsersController } from './users.controller.ts';
import { UsersService } from './users.service.ts';

@Module({
  controllers: [UsersController],
  providers: [UsersService]
})

export class UsersModule {}

From the preceding file, we are exported a UsersModule that contains both the UsersController and UsersService. With this in place, we can then proceed to import and use the UsersModule within the root module of the application as shown in the following code snippet:

从上面的文件,我们出口了UsersModule同时包含UsersControllerUsersService 。 完成此操作后,我们可以继续在应用程序的根模块中导入和使用UsersModule ,如以下代码片段所示:

...
import { UsersModule } from './users/users.module';

@Module({
  ...
})

export class AppModule { }

其他重要概念 ( Other important concepts )

DTO (DTO)

Data transfer object is an object that defines how data will be sent over the network.

数据传输对象是定义如何通过网络发送数据的对象。

介面 (Interfaces)

TypeScript interfaces are used for type-checking and defining the types of data that can be passed to a controller or a Nest service.

TypeScript接口用于类型检查和定义可以传递给控制器​​或Nest服务的数据类型。

依赖注入 (Dependency injection)

Dependency injection is a design pattern used to increase efficiency and modularity of applications. It is often used by the biggest frameworks to keep code clean and easier to use. Nest.js also makes use of it to basically create coupled components.

依赖注入是一种用于提高应用程序效率和模块化的设计模式。 最大的框架通常使用它来保持代码的清洁和易于使用。 Nest.js也利用它来基本创建耦合组件。

With this pattern, it is very easy to manage dependencies between building blocks like controllers, providers and modules. The only thing required is to define the dependency for example a UsersService() in the constructor of a controller as shown here:

通过这种模式,管理诸如控制器,提供程序和模块之类的构建块之间的依赖性非常容易。 唯一需要做的就是在控制器的构造函数中定义依赖项,例如, UsersService() ,如下所示:

...
@Controller('users')
export class UsersController {
constructor(private readonly usersService: UsersService){}
 ...
}

With some of these concepts briefly covered, you can now proceed to the next section, where you will put all the knowledge gained so far in this post into use as you will learn how to seamlessly build a RESTful API using Nest.js.

在简要介绍了其中一些概念之后,您现在可以进入下一节,在这里您将把到目前为止所获得的所有知识投入使用,同时还将学习如何使用Nest.js无缝构建RESTful API。

您将使用Nest.js构建的内容 ( What you will build with Nest.js )

As stated earlier in this post, you will create a sample application that will help you get a good grasp on some of the core concepts of Nest.js.

如本文前面所述,您将创建一个示例应用程序,以帮助您更好地了解Nest.js的一些核心概念。

This application will be specifically for a bookstore. At the end of the post you would have created a micro-service that will enable users to create and add a new book with few descriptions to an existing list of books. This could be from a database, but to ensure simplicity in this post, we won’t really be connecting our application to a database yet. But instead, we will make use of a mock data of books and once a new book is created, we will push and add it to the list.

该应用程序将专门用于书店。 在文章的结尾,您将创建一个微服务,该服务将使用户能够创建新书并向其现有书单添加很少的描述。 这可能来自数据库,但是为了确保本文的简洁性,我们还不会真正将应用程序连接到数据库。 但是,相反,我们将使用书籍的模拟数据,一旦创建了新书籍,我们将其推送并添加到列表中。

安装Nest.js ( Installing Nest.js )

In order to easily scaffold a new Nest.js application, you will need to globally installed Nest CLI. It is a command line interface tool specifically created to amongst other things, help to craft a new Nest.js app in no time and provide access to ( built in generators ) several commands to generate different files and produce a well-structured application.

为了轻松构建新的Nest.js应用程序,您需要全局安装Nest CLI 。 它是一个命令行界面工具,专门用于除其他外,可帮助您立即制作新的Nest.js应用程序,并提供对(内置生成器的)多个命令的访问权限,以生成不同的文件并生成结构良好的应用程序。

Apart from using the CLI tool, you can also install a new Nest.js application by cloning the starter project from GitHub using Git, but for the purpose of this tutorial run the following command to install the Nest CLI:

除了使用CLI工具之外,您还可以通过使用GitGitHub克隆启动项目来安装新的Nest.js应用程序,但出于本教程的目的,请运行以下命令来安装Nest CLI:

npm i -g @nestjs/cli

This will give you access to the nest command for project installation and other project specific commands.

这将使您可以访问用于安装项目的nest命令和其他特定于项目的命令。

Next, run the command below to install a new project named bookstore-nest within your development folder:

接下来,运行以下命令以在开发文件夹中安装一个名为bookstore-nest的新项目:

nest new bookstore-nest

You will be asked few questions during the installation, just follow the prompt and respond accordingly. Next, once the installation is complete, change directory into the newly created project and start the application with:

在安装过程中,系统将询问您几个问题,只需按照提示进行操作,然后做出相应的响应即可。 接下来,安装完成后,将目录更改为新创建的项目,并使用以下命令启动应用程序:

// change directorycd bookstore-nest


// start the application
npm run start

or better still, run the command below in order to use Nodemon for the project:

或更妙的是,运行以下命令以将Nodemon用于项目:

// start the application using nodemonnpm run start:dev

Navigate to http://localhost:3000 from your favorite browser, you will see the Hello World! message as shown here:

从您喜欢的浏览器导航到http:// localhost:3000 ,您将看到Hello World ! 消息如下所示:

生成模块 ( Generate a module )

First you will start by generating a module for the bookstore. To do this, you will leverage the inbuilt file generator using Nest CLI. Run the following command to scaffold a new module for the application:

首先,您将从为书店生成模块开始。 为此,您将使用Nest CLI利用内置文件生成器。 运行以下命令为应用程序搭建新模块:

nest generate module books

The command above will create a new folder named books within the src folder. Also within the books folder you will find a books.module.ts file.

上面的命令将在src文件夹中创建一个名为books的新文件夹。 同样在books文件夹中,您将找到一个books.module.ts文件。

// ./src/books/books/module.ts

import { Module } from '@nestjs/common';
@Module({})
export class BooksModule {}

This was generated by the command and the module has also been added to the app.module.ts which happens to be the root module of the application.

这是由命令生成的,并且该模块也已添加到app.module.ts ,它恰好是应用程序的根模块。

建立路线 ( Create routes )

Next, you will create routes for the endpoints. As mentioned earlier, routes are in controllers, so you need to create controllers that will handle individual endpoints. Again, use Nest CLI to generate your controllers, run the following command:

接下来,您将为端点创建路由。 如前所述,路由位于控制器中,因此您需要创建将处理各个端点的控制器。 同样,使用Nest CLI生成控制器,运行以下命令:

nest generate controller books

This will create a controller inside the books folder. Since we won’t really be connecting to the database for now, create a sample mock data for the bookstore. Under the src folder, create a subfolder named mocks and within the newly created folder, create a new TypeScript file named books.mock.ts and paste the following code in it:

这将在books文件夹内创建一个控制器。 由于我们暂时不会真正连接到数据库,因此为书店创建一个示例模拟数据。 在src文件夹下,创建一个名为mocks的子文件夹,并在新创建的文件夹内,创建一个名为books.mock.ts的新TypeScript文件,并将以下代码粘贴到其中:

// ./src/mocks/books.mock.ts
export const BOOKS = [
    { id: 1, title: 'First book', description: "This is the description for the first book", author: 'Olususi Oluyemi' },
    { id: 2, title: 'Second book', description: "This is the description for the second book", author: 'John Barry' },
    { id: 3, title: 'Third book', description: "This is the description for the third book", author: 'Clement Wilfred' },
    { id: 4, title: 'Fourth book', description: "This is the description for the fourth book", author: 'Christian nwamba' },
    { id: 5, title: 'Fifth book', description: "This is the description for the fifth book", author: 'Chris anderson' },
    { id: 6, title: 'Sixth book', description: "This is the description for the sixth book", author: 'Olususi Oluyemi' },
];

设置服务 ( Setting up service )

Next, you will create a service to hold all the logic for the bookstore. Run the following command to generate a service:

接下来,您将创建一个服务来保存书店的所有逻辑。 运行以下命令以生成服务:

nest generateservice books

This command will create a new file named books.service.ts within ./src/books folder.

此命令将在./src/books文件夹中创建一个名为books.service.ts的新文件。

取得书籍 ( Get books )

Next, open the newly created file and paste the following:

接下来,打开新创建的文件并粘贴以下内容:

//  ./src/books/books.service.ts

  import { Injectable, HttpException } from '@nestjs/common';
  import { BOOKS } from '../mocks/books.mock';

  @Injectable()
  export class BooksService {
      books = BOOKS;

      getBooks(): Promise<any> {
          return new Promise(resolve => {
              resolve(this.books);
          });
      }
      getBook(bookID): Promise<any> {
          let id = Number(bookID);
          return new Promise(resolve => {
              const book = this.books.find(book => book.id === id);
              if (!book) {
                  throw new HttpException('Book does not exist!', 404);
              }
              resolve(book);
          });
      }
  }

First, you imported the requires modules from Nest.js and also BOOKS from the mock data you created earlier.

首先,您从Nest.js导入了require模块,还从先前创建的模拟数据中导入了BOOKS

Next, you created two different methods named getBooks() and getBook() to retrieve the list of books from the mock data and to fetch just one book using the bookID as a parameter.

接下来,创建了两个名为getBooks()getBook()不同方法,以从模拟数据中检索书籍列表,并使用bookID作为参数仅获取一本书。

新增书籍 ( Add book )

Next, add the method below to the /src/books/books.service.ts immediately after the getBook() method:

接下来,在getBook()方法之后立即将以下方法添加到/src/books/books.service.ts

//  ./src/books/books.service.ts

import { Injectable, HttpException } from '@nestjs/common';
import { BOOKS } from '../mocks/books.mock';
@Injectable()
export class BooksService {
    books = BOOKS;
    ...
    addBook(book): Promise<any> {
        return new Promise(resolve => {
            this.books.push(book);
            resolve(this.books);
        });
    }
}

The method above will be used to push a new book to the existing list

上面的方法将用于将新书推送到现有列表中

删除书 ( Delete book )

Finally, add the last method to delete a particular book using the bookID as a parameter:

最后,添加最后一种方法,使用bookID作为参数删除特定的书:

//  ./src/books/books.service.ts

import { Injectable, HttpException } from '@nestjs/common';
import { BOOKS } from '../mocks/books.mock';
@Injectable()
export class BooksService {
    books = BOOKS;
    ...
    deleteBook(bookID): Promise<any> {
        let id = Number(bookID);
        return new Promise(resolve => {
            let index = this.books.findIndex(book => book.id === id);
            if (index === -1) {
                throw new HttpException('Book does not exist!', 404);
            }
            this.books.splice(1, index);
            resolve(this.books);
        });
    }
}

将服务注入控制器 ( Inject service into controller )

Here, you will use dependency injection design pattern to pass the BooksService into the BooksController through a constructor. Open the BooksController created earlier and paste the following code in it:

在这里,您将使用依赖项注入设计模式通过构造函数将BooksController传递到BooksService 。 打开BooksController创建的BooksController ,并将以下代码粘贴到其中:

// ./src/books/books.controller.ts

import { Controller, Get, Param, Post, Body, Query, Delete } from '@nestjs/common';
import { BooksService } from './books.service';
import { CreateBookDTO } from './dto/create-book.dto';

@Controller('books')
export class BooksController {
    constructor(private booksService: BooksService) { }

    @Get()
    async getBooks() {
        const books = await this.booksService.getBooks();
        return books;
    }

    @Get(':bookID')
    async getBook(@Param('bookID') bookID) {
        const book = await this.booksService.getBook(bookID);
        return book;
    }

    @Post()
    async addBook(@Body() createBookDTO: CreateBookDTO) {
        const book = await this.booksService.addBook(createBookDTO);
        return book;
    }

    @Delete()
    async deleteBook(@Query() query) {
        const books = await this.booksService.deleteBook(query.bookID);
        return books;
    }
}

Here in this controller, first, the important modules were imported from @nestjs/common and you also import both the BooksService and CreateBookDTO respectively. CreateBookDTO is a data transfer object, a TypeScript class created for type-checking and to define the structures of what an object looks like when creating a new book. We will create this DTO in a bit.

在此控制器中,首先,重要模块是从@nestjs/common导入的,您还分别导入了BooksServiceCreateBookDTO 。 CreateBookDTO是一个数据传输对象,它是一个TypeScript类,用于类型检查并定义对象在创建新书时的外观结构。 我们将稍后创建此DTO。

Next, you used constructor to inject the BooksService into the controller and created four different methods which are:

接下来,您使用constructorBooksService注入到控制器中,并创建了四个不同的方法:

  • getBooks(): Used to fetch the list of all books. It has @Get() decorator attached to it. This helps to map any GET request sent to /books to this controller.

    getBooks() :用于获取所有书籍的列表。 它具有@Get()装饰器。 这有助于将发送到/ books的任何GET请求映射到此控制器。

  • getBook(): Used to retrieve the details of a particular book by passing the bookID as a parameter.

    getBook() :用于通过将bookID作为参数来检索特定书籍的详细信息。

  • addBook(): Used to create and post a new book to the existing book list. And because we are not persisting into the database, the newly added book will only be held in memory.

    addBook() :用于创建新书籍并将其发布到现有书籍列表中。 而且由于我们没有持久化到数据库中,因此新添加的书将仅保存在内存中。

  • deleteBook(): Used to delete a book by passing the bookID as a query parameter.

    deleteBook() :用于通过传递bookID作为查询参数来删除一本书。

Each of the methods has a special decorator attached to it, which makes it very easy to route each HTTP request to a specific method within the controller.

每个方法都有一个附加的特殊装饰器,这使得将每个HTTP请求路由到控制器内的特定方法非常容易。

DTO ( The DTO )

In the previous section, you made use of a data transfer object called CreateBookDTO. To set it up, navigate to the ./src/books folder and create a new subfolder name dto. Next, within the newly created folder, create another file and call it create-book.dto.ts and paste the following in it:

在上一节中,您使用了一个名为CreateBookDTO的数据传输对象。 要进行设置,请导航到./src/books文件夹并创建一个新的子文件夹名称dto 。 接下来,在新创建的文件夹中,创建另一个文件,并将其命名为create-book.dto.ts并将以下内容粘贴到其中:

// ./src/books/dto/create-book.dto.ts

export class CreateBookDTO {
    readonly id: number;
    readonly title: string;
    readonly description: string;
    readonly author: string;
}

You are almost done with the application, the next line of action is to take a look at the BooksModule and update it accordingly. You will do that in the next section.

您几乎完成了该应用程序,下一步是查看BooksModule并相应地BooksModule进行更新。 您将在下一部分中进行操作。

更新书籍模块 ( Update the books module )

Navigate back to the BooksModule created earlier and update it with the code below:

导航回到BooksModule创建的BooksModule ,并使用以下代码对其进行更新:

// ./src/books/books.module.ts

import { Module } from '@nestjs/common';
import { BooksController } from './books.controller';
import { BooksService } from './books.service';
@Module({
  controllers: [BooksController],
  providers: [BooksService]
})
export class BooksModule {}

测试应用 ( Test the application )

Start the application again if it is not running at the moment with:

如果当前没有运行,请再次启动该应用程序:

npm run start

and use postman to test the API

并使用邮递员测试API

取得书籍 ( Get Books )

使用bookID获取图书 ( Get book using bookID )

新建一本书 ( Create a new book )

删除书籍 ( Delete a book )

结论 ( Conclusion )

We have barely scratched the surface on what Nest.js has to offer the Node.js world in this post. To get more conversant with this awesome framework, first, we took a quick look at the fundamentals and basic building blocks of Nest.js and then proceeded to build a RESTful API where you also learnt about dependency injection amongst other things.

在本文中,我们几乎没有涉及Nest.js提供Node.js世界的内容。 为了更好地了解这个令人敬畏的框架,我们首先快速了解了Nest.js的基础知识和基本构建块,然后着手构建RESTful API,您还从中了解了依赖注入。

I hope this tutorial as given you enough information to try out Nest.js for your next application. Feel free to drop your thoughts in the comment section below and find the complete source code of this tutorial here on GitHub.

我希望本教程能为您提供足够的信息,以便为您的下一个应用程序试用Nest.js。 欢迎在下面的评论部分中发表您的想法,并在GitHub上找到本教程的完整源代码。

翻译自: https://scotch.io/tutorials/getting-started-with-nestjs

nest.js

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值