Benjamin Benjamin - 1 year ago 706
Node.js Question

Node.Js-Getting current windows username

I have an ASP.Net MVC project, and I am trying to get the client windows username (the client side is always running on Windows machine) and pass the windows username to the server side using Node.JS.
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.

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download