API with NestJS #26. Real-time chat with WebSockets

API with NestJS #26. Real-time chat with WebSockets

API with NestJS #26. Real-time chat with WebSockets - In this article we look into what are WebSockets and implemenet a simple real-time chat functionality.

  • 1.  API with NestJS #1. Controllers, routing and the module structure
  • 2.  API with NestJS #2. Setting up a PostgreSQL database with TypeORM
  • 3.  API with NestJS #3. Authenticating users with bcrypt, Passport, JWT, and cookies
  • 4.  API with NestJS #4. Error handling and data validation
  • 5.  API with NestJS #5. Serializing the response with interceptors
  • 6.  API with NestJS #6. Looking into dependency injection and modules
  • 7.  API with NestJS #7. Creating relationships with Postgres and TypeORM
  • 8.  API with NestJS #8. Writing unit tests
  • 9.  API with NestJS #9. Testing services and controllers with integration tests
  • 10.  API with NestJS #10. Uploading public files to Amazon S3
  • 11.  API with NestJS #11. Managing private files with Amazon S3
  • 12.  API with NestJS #12. Introduction to Elasticsearch
  • 13.  API with NestJS #13. Implementing refresh tokens using JWT
  • 14.  API with NestJS #14. Improving performance of our Postgres database with indexes
  • 15.  API with NestJS #15. Defining transactions with PostgreSQL and TypeORM
  • 16.  API with NestJS #16. Using the array data type with PostgreSQL and TypeORM
  • 17.  API with NestJS #17. Offset and keyset pagination with PostgreSQL and TypeORM
  • 18.  API with NestJS #18. Exploring the idea of microservices
  • 19.  API with NestJS #19. Using RabbitMQ to communicate with microservices
  • 20.  API with NestJS #20. Communicating with microservices using the gRPC framework
  • 21.  API with NestJS #21. An introduction to CQRS
  • 22.  API with NestJS #22. Storing JSON with PostgreSQL and TypeORM
  • 23.  API with NestJS #23. Implementing in-memory cache to increase the performance
  • 24.  API with NestJS #24. Cache with Redis. Running the app in a Node.js cluster
  • 25.  API with NestJS #25. Sending scheduled emails with cron and Nodemailer
  • 26. API with NestJS #26. Real-time chat with WebSockets
  • 27.  API with NestJS #27. Introduction to GraphQL. Queries, mutations, and authentication
  • 28.  API with NestJS #28. Dealing in the N + 1 problem in GraphQL
  • 29.  API with NestJS #29. Real-time updates with GraphQL subscriptions
  • 30.  API with NestJS #30. Scalar types in GraphQL
  • 31.  API with NestJS #31. Two-factor authentication

With WebSockets, we can perform a two-way communication in real-time between the user and the server. Thanks to that, the browser can send messages to the server and listen to information from the other side.

The principles of the WebSocket handshake

WebSocket is a protocol that operates in a different way than HTTP. Even though that’s the case, establishing the connection begins with the client sending an HTTP call that we call a handshake.

The server listens for incoming socket connections using a regular TCP socket. The client sends a GET request to the URL of our socket.

Request URL : ws ://localhost:8080/

Request Method : GET

####### Request headers:

Headers : Connection : Upgrade

Upgrade : websocket

Sec - WebSocket - Key : 2GruKa / C487njkWNw2HKxQ ==

javascript nestjs typescript

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

What is TypeScript? Why TypeScript? and Why Not TypeScript?

TypeScript extends JavaScript by adding Types. There are many great reasons to switch to TypeScript. Especially if your team uses JavaScript. There are some reasons to not use TypeScript as there are with any language or framework.

Building Modern Nodejs Application using Nestjs and TypeScript

Building Modern Nodejs Application using Nestjs and TypeScript - In this article, we will see how to build REST API using Nestjs with TypeScript. Building Modern Nodejs Application using Nestjs and TypeScript

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

Hire dedicated JavaScript Developers who are proficient in AngularJS, ReactJS, NodeJS, & VueJS frameworks. Get flexible hiring models as per your business requirements.

TypeScript Tutorial For JavaScript Developers - TypeScript Basics

TypeScript Tutorial For JavaScript Developers - TypeScript Basics. I will show you guys 4 example of JavaScript code, and how to convert it to TypeScript. This is a typescript beginners tutorial.

Developing REST API Framework using TypeScript and NestJS

Nowadays, web applications are being designed with REST API and front-end. For developing a UI application, now, we have so many popular JavaScript frameworks available, like Angular, React, Vue and many more. For developing REST API, we have multiple options too. If we select Java as a programming language, we have Spring boot; for .NET, we have REST API Framework; if we choose JavaScript, then we have ExpressJS, HapiJS, and NestJS etc