Benjamin Benjamin - 8 months ago 310
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.


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);