Find OS username in NodeJS

drowZ picture drowZ · Nov 4, 2016 · Viewed 28.9k times · Source

How would I find the username that the computer owner is using currently (while logged in), using NodeJS?

I have searched around a bit, but haven't found anything...

Answer

drowZ picture drowZ · Nov 4, 2016

I am not sure why, but someone added an answer and then deleted it quickly after... I was fast enough to catch it though, and after checking, it is the shortest and most effective way of doing what I asked before:

require("os").userInfo().username

The only problem is, in Windows 10, it returns the first name of the owner account that has been used (just a heads up). Everything else works completely fine!