How to handle sessions in node.js without frameworks

I am working on SPA (single page web application); the idea was to make things easier and not use too many frameworks and abstractions, etc., so I created an HTTP server for static + dynamic files, and it works well. Now I have implemented socket.io in a web application, but I would like to know what, in your opinion, would be a good way to handle sessions (bearing in mind that socket io should be able to identify the user who calls the functions and knows who should push data). Hope I was clear enough :)

+5
source share
1 answer

Socket.io has built-in methods for saving session server data for a given socket through socket.get, socket.setand socket.del. Where it stores this data, the storage device is used by default, but you can use redis, etc. Keep in mind that when the socket is disconnected, this data is not saved when reconnecting, so you will want to send client identification data using the socket installation event or during authorization.

This way, it leaves your client data that can be saved via localStorage, sessionStorage or regular old vanilla cookies, among others.

+1
source

All Articles