Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.Js - Get windows username

Tags:

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.

like image 906
Benjamin Avatar asked Jan 12 '15 04:01

Benjamin


People also ask

How do I find my node JS username?

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.

How do I find my Windows browser username?

In the box, type cmd and press Enter. The command prompt window will appear. Type whoami and press Enter. Your current user name will be displayed.

What is OS username?

os_username is the operating system account. username is the database account.

What is process ENV user?

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 .


1 Answers

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); 
like image 173
Karthik M Avatar answered Sep 20 '22 13:09

Karthik M