Next.js Discord

Discord Forum

Server sent events

Answered
Polar bear posted this in #help-forum
Open in Discord
Avatar
Polar bearOP
Is it possible to create a realtime using server sent events in nextjs?
If it is, is there a library or guide on this topic?
Answered by B33fb0n3
yes you can. But only with a serverfull enviorement. Nextjs itself works mostly via server functions and these will be run only for some seconds.

So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
View full answer

8 Replies

Avatar
yes you can. But only with a serverfull enviorement. Nextjs itself works mostly via server functions and these will be run only for some seconds.

So create a serverfull enviorement and connect to it via a client (browser). Now you can send and retrieve events from the server
Answer
Avatar
Polar bearOP
Isn't remix like nextjs run for some seconds, I have made it in remix in the same app.
I don't fully understand what is serverfull, do you mean I need to create another server like a node app server?
Avatar
nextjs functions run only for a few seconds. But you want a constant connection. Not a connection that least only a few seconds. When deploying on vercel for example you only get a serverless enviorement (as said: function that only run for a few seconds). A serverfull enviorement is a real server, that holds your connections and stays online. That can be a VPS for example
Avatar
Polar bearOP
Then the issue is where I will deploy it, not with the nextjs app
?
Avatar
you can still deploy it on vercel, but the connection (where your client, your browser connects to) can't be to vercel. You need an extra server for that. That can be a VPS for example
Avatar
Polar bearOP
Ok, thanks. I'll search that.
Avatar
happy to help