I am trying to get the windows username of the machine that is running my node.jS app (the app is always running on a Windows machine).
How can I get the current windows username using Node.Js?
I am trying to find something similar to WindowsIdentity.GetCurrent().Name in C# for node.js, or whoamI command in CMD.
Since Node v6 (2016-04), you can just use os.userInfo :
var os = require('os');
os.userInfo().username
To get the current logged-in username:
var path = require('path');
var userName = process.env['USERPROFILE'].split(path.sep)[2];
var loginId = path.join("domainName",userName);
console.log(loginId);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments