The basic logic for handling sessions is:
- Create a place to put the data for all the sessions. e.g. an object in memory or a database.
- Pick a cookie name to store session IDs in
- If a request comes in with no cookie of that name:
- Generate a unique id
- Create a space with that ID as its name in the store
- Set the cookie with the given name and ID
- If a request comes in with a cookie of that name:
- Read the data associated with that ID from the store
Then you need to expire old sessions to clean up their data, and add error checking for when a request for a non-existent session comes in. You'll probably want to enhance security by restricting access to a session to the IP address that originally created it. Etc.
This is a bunch of work. The reason you keep finding Express related results is because it is a solved problem so you can use Express and a session middleware and not have to reinvent this wheel.