In our actual business development, we often need the back end to actively notify the front end. The more traditional approach is to write a timer on the front end to continuously poll and adjust the back end interface. In this way, the back end interface is called frequently, and the performance is much worse. Bring burden, I will introduce websocket
the use from several business scenarios below
- Simulate double eleven e-commerce platform to submit an order, and then notify the front-end that the order is successful
- Use broadcast to realize the group chat function, and everyone can see the messages you send. Common businesses are usually system notifications
- Group (room) function, only those who join the room can receive the corresponding message
One, configure the front-end template engine
-
1. Install the
ejs
template enginenpm install ejs --save
-
2. Configure the template engine in the project
// main.ts中 import { NestFactory } from '@nestjs/core'; import