Remix - How to add websocket to my project

Viewed 877

I started a indie stack project on remix.run and I would like to add websocket.io. I would like to deploy in the future to Netlify. Could you please help me, I am new and do not really know what to do.

I found that it is possible to start a indie stack project with the "express" option but I do not know if it will be compatible with netlify.

1 Answers

As far as I know, socket.io requires a long-running server. A serverless environment such as Netlify functions won't work. There are ways to make websocket connections on AWS Lambda but I am not sure socket.io supports such configurations. Netlify and Vercel for sure don't (at this point).

For now, use Remix with the express adapter. Pick a stack that works with express and then you can simply integrate socket.io like you would on any other express server and React client project.

You can find a great Remix with socket.io example in the examples folder of Remix GitHub repository.

There is an ongoing discussion about native websocket support in Remix. However, since websockets won't work on most serverless environments, it's unlikely at this moment that websockets will make it into Remix.

However, it seems like the Remix team is working on introducing Server-Sent-Events (SSE) to its fetch API. SSE can work as an alternative to websockets. Maybe that could be an alternative for future readers. You can find the discussion here.

Related