websocket guide
Unanswered
Allen's Hummingbird posted this in #help-forum
Allen's HummingbirdOP
I am confused what is the way to use websockets in NextJs,
I would like to host websocket server within NextJs.
It's okay if I won't be able to this but I still don't understand what is the optimal way to achieve all this ?
I would like to host websocket server within NextJs.
It's okay if I won't be able to this but I still don't understand what is the optimal way to achieve all this ?
10 Replies
@Allen's Hummingbird I am confused what is the way to use websockets in NextJs,
I would like to host websocket server within NextJs.
It's okay if I won't be able to this but I still don't understand what is the optimal way to achieve all this ?
If you are going to host nextjs on serverless platforms like vercel, you cannot host your own websocket server but can connect to one just fine client side. If you still want real time functionality, you can take a look at pusher
@Naeemgg Go VPS
Allen's HummingbirdOP
yeah but what is the way to do it,
in a nextjs app
I beleive you're talking about doing it within app router correct
Allen's HummingbirdOP
yes
You can create a route.ts somewhere in app like
/app/api/socket/route.tsAnd this will be your socket server
Now emit and receive events from here
Just like we do in express