15

Adding Persistence to Socket.IO Using MongoDB

Now that we have implemented a Socket.IO backend and frontend, let’s spend some time integrating it with the MongoDB database by temporarily storing messages in the database and replaying them when a new user joins, so that users can see the chat history after they join. Additionally, we will refactor our chat app to be ready for future expansions and maintenance. Finally, we will test out the new structure by implementing new commands to join and switch rooms.

In this chapter, we are going to cover the following main topics:

  • Storing and replaying messages using MongoDB
  • Refactoring the app to be more extensible
  • Implementing commands to join and switch rooms

Technical requirements

Before we start, ...

Get Modern Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.