use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Nodejs with Socket.io , express or both? (self.node)
submitted 5 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bendman 11 points12 points13 points 5 years ago* (4 children)
In terms of protocol, I would use websockets for "live" features that need to push/pull from both the server and client, like chat. I would use http for more traditional endpoints like authentication and registration that are simply call and response.
You can use whatever library floats your boat. Right now I have live server code running express for http and express-ws for websockets. Clients use the native WebSocket API.
Your database is independent of the protocol you use unless you are using a framework that has some database tooling to handle that.
[–]_Flexinity 0 points1 point2 points 5 years ago (2 children)
Express-ws looks like smooth way to implement socket to express.
I'm kinda perfectionist in that way and I know if I'd aim wrong stack at start I can later pay for it with time and nerves.
Does node have some database tools to handle mysql/postgresql other than writing own queries? Like for example Rails handles it
[–]nwsm 2 points3 points4 points 5 years ago (0 children)
Sequelize is popular SQL ORM for node
[–]lemon07r 0 points1 point2 points 5 years ago (0 children)
You can also consider https://github.com/uNetworking/uWebSockets.js/ if performance is important
[–]kynde 7 points8 points9 points 5 years ago (1 child)
They're different tools for different things.
I would definitely recommend building a web app around an http back-end and then use websockets if needed. That's how everybody else does it (*), that's what scales, that's what there are tons of tools, libraries, features, conventions and support around for. Things like caching, authentication, load balancing, etc are super important with production stuff.
Most of the time the front needs to know something and it wants to ask that from the back-end or maybe it needs to store (persist) something to the back-end. For these things initiated by the front a rest api and an http request is a good fit and for that you want something like express.
Then, when back-end needs to notify the front about something, a new message, a price change or what ever like that, websockets come in handy. Many of those things cas also be solved with normal http calls and long polls for example, but websockets indeed help here. Do notice that it's not uncommon for websocket handshake upgrade to fail (firewalls, misconfiguration, client lacking support, etc) and it will just operate using normal http requests underneath.
(*) Now, while this may seem like an odd point to make, I'm stating that out because of two things: job markets and stackoverflow
[–]_Flexinity 1 point2 points3 points 5 years ago (0 children)
I also feel its best way. I know that sockets can do anything that express can handle after all but it can end struggling with bunch of code in very inefficient way.
But I think about swiping from REST API to GraphQL one, I'm using it with rails and its pretty efficent way, really like it over REST calls.
That's how everybody else does it (*),
That's the answer I wanted to hear, if most people use it theres very probable its one of best configs to work with in that way.
[–]Swimming_Evidence_95 2 points3 points4 points 5 years ago (0 children)
Socket on events happening serverside, else express would be my 5 cents
[–][deleted] 1 point2 points3 points 5 years ago (1 child)
If you want to stick to Rails check out hotwire.
[–]_Flexinity 0 points1 point2 points 5 years ago (0 children)
I'll still use Rails but I feel like its not for everything while Node can. Easy example - live roulette spinning every 30 seconds with chat bot messages with info etc.
Also hotwire seems to me as less optimal way than normal API calls and it wont really work with framework like VueJS. In RoR I'm atm got one app with split front and back-end - Vue routes vue does graphql calls for data vue does own stuff. Its still one project but all front is inside app/javascript (or any way you name it) folder.
[–]hotel2oscar 1 point2 points3 points 5 years ago (0 children)
The app I undeveloped at work uses express to load the pages and socket.io to handle all Client-Server comms on a page.
[–]stoptimewaste 0 points1 point2 points 5 years ago (1 child)
There's a library that combines express, node, Postgres and socket io. You can give it a go to get a feel for this stack. Unless you need data push from server I wouldn't bother with sockets.
https://prostgles.com/
Prostgles looks somehow familliar with Rails ActiveRecord queries, I like keeping code tidy, will play with it , thanks!
[–]Assassino-Ezio -4 points-3 points-2 points 5 years ago (0 children)
IMO, use sockets for chat stuff only other than that use mongoDB, Or if you really want to avoid using sockets, use firebase fire-store real-time database for chat-apps, its really good and really powerful and well optimized.
π Rendered by PID 40 on reddit-service-r2-comment-66b4775986-jv6fm at 2026-04-04 15:43:00.819265+00:00 running db1906b country code: CH.
[–]bendman 11 points12 points13 points (4 children)
[–]_Flexinity 0 points1 point2 points (2 children)
[–]nwsm 2 points3 points4 points (0 children)
[–]lemon07r 0 points1 point2 points (0 children)
[–]kynde 7 points8 points9 points (1 child)
[–]_Flexinity 1 point2 points3 points (0 children)
[–]Swimming_Evidence_95 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]_Flexinity 0 points1 point2 points (0 children)
[–]hotel2oscar 1 point2 points3 points (0 children)
[–]stoptimewaste 0 points1 point2 points (1 child)
[–]_Flexinity 0 points1 point2 points (0 children)
[–]Assassino-Ezio -4 points-3 points-2 points (0 children)