最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to implement Socket.io with next.js without separate node server - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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.

发布评论

评论列表(0)

  1. 暂无评论