How would I get/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.
To get the OS current user id or ( uid ) in Node. js, you can use the userInfo() method from the os module and then use the uid property from the object returned.
you can do it w/ very small java applet that has to signed you just need System. getProperty("user.name") The solution will work on any browser supporting java.
js/JavaScript code. To launch the REPL (Node shell), open command prompt (in Windows) or terminal (in Mac or UNIX/Linux) and type node as shown below. It will change the prompt to > in Windows and MAC. You can now test pretty much any Node.
process. env is the process's environment variables, which are supplied by the OS to the process. This object can really contain just about anything, as specified the OS and the process that launches it, but by default Windows stores the username in USERNAME and Unix-like systems (Linux, macOS, etc.) store it in USER .
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!
This one object you will get username:
let os = require('os') console.log(os.userInfo());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With