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?
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?
Share Improve this question asked Dec 23, 2020 at 9:16 Nasir KhanNasir Khan 8131 gold badge11 silver badges22 bronze badges 3- 1 When I google "nextjs socket.io" I get a bunch of promising results; have you looked into these yet? – user5734311 Commented Dec 23, 2020 at 9:20
- Yes. But none of them are satisfactory for me!! – Nasir Khan Commented Jan 6, 2021 at 9:09
- You need to add to your question the specific code you've tried, and a description of why it fails, including relevant error messages. – user5734311 Commented Jan 6, 2021 at 10:44
2 Answers
Reset to default 4You 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.
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.