Creating a SwiftUI Chat app using Laravel and Socket.IO — Part 2
2 min readNov 13, 2019
In Part 1 we set up all the endpoints for our chat! But our chat isn’t real-time yet. We are going to use Socket.IO to make our API realtime. Let's get started!
Installing Socket.IO
As I mentioned above, we are going to use Socket.io to make the chat realtime. To install socket.IO we are going to run
npm init
npm install socket.ionpm install express
npm install ioredis
What are the other two packages? Well, we are going to need Redis and express later on. Redis will be picking up the queues and sending It to the app via sockets.
Installing Redis
As mentioned above we are going to need Redis to notify our sockets that there is a new message
//This command can be different based on your OS
brew install redis
Socket IO file
Create a new file in the main directory called server.js and type this
var app = require('express')();var http = require('http').Server(app);var io = require('socket.io')(http);var Redis = require('ioredis');var redis = new Redis();io.on('connection', function(socket) {//console.log('New Connection!');