Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Socket.io with next.js without separate node server

I want to build a chat system with Next.js. I am not sure how I have to setup the socket server.

I want this to implement Next server not with a separate server. Should I have to make a server.js file in root and run a server?

like image 738
Nasir Khan Avatar asked Mar 21 '26 13:03

Nasir Khan


2 Answers

You will need to create custom server however, then you can't deploy to vercel, and you got yourself a regular nodejs application. You could use cloud providers to handle sockets for you, or as you said, you could split your application to a regular next.js app and deploy your socket application separately.

like image 125
Ivan V. Avatar answered Mar 23 '26 05:03

Ivan V.


Yes. It is possible to use socket.io on the same server as next.js.

I have created a github repo implementing this thing. It is a very simple and working starter template for Next.js and socket.io.

like image 25
Bibek Oli Avatar answered Mar 23 '26 04:03

Bibek Oli