The easiest way to store session value

Sorry for being very stupid, but I really can't get my head around it. There are many different options like Cookies, LocalStorage, LocalForage, Session Cookies, etc.

What I need though is to store user information, and I have to do it on the server (I'm using node and express), I mean I can determine user on the server, and I have to send it to the client, and store it in browser's session store.

And I can't use just regular cookies, I don't want to persist that between the sessions.

with the cookie I could just do:

apt.get '/', (req, res)->
   res.cookie 'user', currentUser

But doing similar thing with res.session doesn't work

Update after discussion.

Sounds like you should look at the basic approach of:

  • Take the user data you have on the server but want available in the browser, serialize it to JSON on the server
  • transfer that user JSON data to the browser in an HTML <script> tag whenever there's a full page load. Something like <script>window.USER = {"name": "Agzam"};</script>
  • when your JS on the page starts to run, you have access to it directly: window.USER

You can just leave it there in memory and it will go away when the window/tab is closed.

I recommend sharify as a secure and convenient way to do this. It integrates with express and browserify. If you don't use sharify, be aware that the rules for properly encoding JSON inside HTML are tricky.

I don't want to persist that between the sessions

Don't use localStorage or anything backed by localStorage then as they will persist longer.