Chapter 8. Web sockets
As you have seen, Nest.js provides a way to use web sockets into your app through the @nestjs/websockets
package. Also, inside the framework the usage of the Adapter
allows you to implement the socket library that you want.
By default, Nest.js comes with it’s own adapter, which allows you to use socket.io
, a well known library for web sockets.
You have the possibility to create a full web socket app, but also, add some web socket features inside your Rest API. In this chapter, we will see how to implement the web socket over a Rest API using the decorators provided by Nest.js, but also how to validate an authenticated user using specific middleware.
The advantage of the web socket is to be able to have some real-time features in an application depending on your needs. For this chapter you can have a look at the /src/gateways
files from the repository, but also /src/shared/adapters
and /src/middlewares
.
Imagine the following CommentGatewayModule
, which looks...