Nest.js: A Progressive Node.js Framework·PDF电子书

Nest.js: A Progressive Node.js Framework·PDF电子书

书籍简介

JavaScript frameworks go in and out of style very quickly as web technologies change and grow. Nest.js is a good starting point for many developers that are looking to use a modern web framework because it uses a language that is very similar to that of the most used language on the web to this day, JavaScript. Nest.js also uses TypeScript, which is a language that provides the simplicity and power of JavaScript with the type safety of other languages you may be used to. The type safety in Nest.js is only available at compile time, because the Nest.js server is compiled to a Node.js Express server that runs JavaScript. This is still a major advantage, however, since it allows you to better design programs error free prior to runtime.

With Nest.js making use of Node.js Express, you have access to each and every one of the Node.js packages when developing Nest applications. Many even have type definitions for their packages that allow IDE’s to read the package and make suggestions/auto fill in code that may not be possible when crossing JavaScript code with TypeScript code. One of the largest benefits of Node.js is the huge repository of modules that are available to pull from instead of having to write your own. Nest.js includes some of these modules already as part of the Nest platform, like @nestjs/mongoose, which uses the NPM library mongoose.

Angular was a heavy inspiration for the development of Nest.js because both use a Module/Component system that allows for reusability. If you are not familiar with Angular, it is a TypeScript-based front-end framework that can be used cross-platform to develop responsive web apps and native apps, and it functions a lot like Nest does. The two also pair very well together with Nest providing the ability to run a Universal server to serve pre-rendered Angular web pages to speed up website delivering times using Server-Side Rendering (SSR) mentioned above. Follow along in this how-to and get up and running with Nest.js.

书籍目录

Preface

What is Nest.js?

1. Introduction

Topics discussed
Nest CLI
Dependency Injection
Authentication
ORM
REST API
WebSockets
Microservices
GraphQL
Routing
Nest specific tools
OpenAPI (Swagger)
Command Query Responsibility Segregation (CQRS)
Testing
Server-side rendering with Angular Universal
Summary

2. Overview

Controllers
Providers
Modules
Bootstrapping
Middleware
Guards
Summary

3. Nest.js authentication

Passport
Manual implementation
Implementation
Authentication middleware
Managing restrictions with guards
Nest.js passport package
Summary

4. Dependency Injection system of Nest.js

Overview of Dependency Injection
Why use Dependency Injection
How it works without Dependency Injection
How it works with a manual Dependency Injection
Dependency Injection pattern today
Nest.js Dependency Injection
The difference between Nest.js and Angular DI
Summary

5. TypeORM

What database to use
About MariaDB
Getting started
Start the database
Connect to the database
Initialize TypeORM
Modelling our data
Our first entity
Using our models
The service
The controller
Building a new module
Improving our models
Auto-generated IDs
When was the entry created?
Column types
NoSQL in SQL
Relationships between data models
How to store related entities
Retrieving related entities in bulk
Lazy relationships
Other kinds of relationships
One-to-one
Many-to-many
Advanced TypeORM
Security first
Other listeners
Composing and extending entities
Caching
Building a query
Building our model from a existing database
Summary

6. Sequelize

Configure Sequelize
Create a model
@Table
@column
Create the User model
LifeCycle hooks
Injecting a model into a service
Usage of Sequelize transaction
Migration
Configuring the migration script
Create a migration
Summary

7. Mongoose

A word about MongoDB
A word about Mongoose
Mongoose and Nest.js
Getting started
Set up the database
Start the containers
Connect to the database
Modelling our data
Our first schema
Using the schema
The interface
The service
The controller
The first requests
Relationships
Modelling relationships
Saving relationships
Reading relationships
Summary

8. Web sockets

WebSocketGateway
Gateways
Authentication
Adapter
Client side
Summary

9. Microservices

Server bootstrap
Configuration
First microservice handler
Sending data
Exception filters
Pipes
Guards
Interceptors
Built-in transports
Redis
MQTT
NATS
gRPC
Custom transport
Hybrid application
Advanced architecture design
Summary

10. Routing and request handling in Nest.js

Request handlers
Generating responses
Standard approach
Express approach
Route parameters
Request body
Request object
Asynchronous handlers
Async/await
Promise
Observables
Error responses
HttpException
Unrecognized exceptions
Summary

11. OpenAPI (Swagger) Specification

Document Settings
Documenting authentication
Swagger UI
API input decorators
@Body
@Param
@Query
@Headers
Authentication
API request and response decorators
API metadata decorators
Saving the swagger document
Summary

12. Command Query Responsibility Separation (CQRS)

Entry module commands
Command handlers
Invoking command handlers
Linking keywords with events
Keyword events
Invoking event handlers
Retrieving keywords APIs
Linking keywords with sagas
Keyword saga commands
Keyword saga
Summary

13. Architecture

Style guide of naming conventions
Controller
Service
Module
Middleware
Exception filter
Pipe
Guard
Interceptor
Custom decorator
Gateway
Adapter
Unit test
E2E test
Directory structure
Server architecture
Angular Universal architecture
Summary

14. Testing

Unit testing
Tooling
Preparation
Writing our first test
Testing for equality
Covering our code in tests
E2E testing
Preparation
Writing end-to-end tests
Summary

15. Server-side Rendering with Angular Universal

Serving the Angular Universal App with Nest.js
Building and running the Universal App
Summary

免责申明:
本网站所有内容资源均来自于互联网收集及网友分享
本网站所有内容资源解释权归原作者或版权方所有,请支持购买官方正版。
如侵犯到您(公司)的合法权益请发送邮件到[email protected](注意:邮件标题请包含反馈二字),我们会第一时间确认并删除相关内容资源。

版权声明:
本网站发布的全部教程内容(包括但不限于文字、视频、图片等)著作权均归原作者或版权方所有。
未经原作者或版权方授权许可,用户不得以任何载体或形式使用其内容。