The "experimental-edge" flag in nextjs allows me to deploy websocket in vercel?

I know that websocket cannot be used in vercel because it is serverless. However, I understand that edge is not serverless, hence my doubt.
6 Replies
whatplan
whatplan2y ago
while the edge runtime is different from the serverless runtime, it is still a temporary instance like serverless websockets require a persistent connection
normigonzalez
normigonzalezOP2y ago
Thank you so much! Another question... could I use websocket in the nextJS API and deploy to something like Heroku or Railway? I know many just use an external server like express, but I would prefer to use everything in the nextjs API. Or at least monorepo.
whatplan
whatplan2y ago
Node.js Runtime Using the Node.js runtime gives you access to all Node.js APIs, and all npm packages that rely on them. However, it's not as fast to start up as routes using the Edge runtime. Deploying your Next.js application to a Node.js server will require managing, scaling, and configuring your infrastructure. Alternatively, you can consider deploying your Next.js application to a serverless platform like Vercel, which will handle this for you.
https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes deploying next on your own is kind of a big hassle probably not worth doing the t3 stack docs reccomend pusher for serverless websockets https://create.t3.gg/en/other-recs#pusher
Rendering: Edge and Node.js Runtimes
Learn about the switchable runtimes (Edge and Node.js) in Next.js.
Create T3 App
Other Recommendations 🚀 Create T3 App
The best way to start a full-stack, typesafe Next.js app.
normigonzalez
normigonzalezOP2y ago
I understand. Rather than using Pusher, I prefer to use a separate server in express which I'm already more familiar with. And in that case, I'm going to have to "manage, scale, and configure my infrastructure" anyway, right?
whatplan
whatplan2y ago
yes, but unless you have a serious amount of traffic "managing, scaling, and configuring your infrastructure" is just clicking the express preset on railway
normigonzalez
normigonzalezOP2y ago
That's what I was going for. Almost all of my backend goes through the websocket (I just have a couple of additional http queries like login, which I guess are negligible). So, since I'm going to have to build a server to be able to use websocket, for that I already put the websocket in nextJS (if possible) and simply deploy to heroku or railway and I "sacrify" the few or no advantages that serverless would offer me in my case . If I could even use API routes and not have to build a custom server that would be great. What do you think of doing something like this? https://stackoverflow.com/a/71415736/10476393 I understand that if I deploy it on a persistent connection it should work right?
Stack Overflow
How can I run a websocket server in next js custom server in dev mode
Assuming I want to run a custom next js server, and to accept websocket connections on that same server, how can I avoid clobbering the next js dev server hot reloading which is also using websocke...
Want results from more Discord servers?
Add your server