How to show if users are online

So this is an optional extra I would like on one of my backend systems to see what staff are logged in.
I have currently figured a way of doing it, however it is reliant on the user logging out.
Problem is unless they click the logout button they still remain logged in (for example if they just close the window).
Is there a way that if the window is closed or the computer is shut down then it could automatically log them out?
Site is NodeJS by the way.

Community Page
Last updated: