Use socket.io in nestjs

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 websocketthe 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 ejstemplate engine

    npm install ejs --save
    
  • 2. Configure the template engine in the project

    // main.ts中
    import {
         
          
           NestFactory } from '@nestjs/core';
    import 

Guess you like

Origin blog.csdn.net/kuangshp128/article/details/111035032