5

I would really know how to output the username in Electron applications. So something like that:

const os = require('os')
const username = // the code or the username so that it can be displayed
document.write("The username is: " + username)

Is that possible?

Rajan Mishra
  • 1,178
  • 2
  • 14
  • 30
Jordy Deweer
  • 311
  • 1
  • 4
  • 13
  • 5
    Possible duplicate of [Find OS username in NodeJS](https://stackoverflow.com/questions/40424298/find-os-username-in-nodejs) – Serge K. Sep 20 '17 at 07:55

3 Answers3

14

Out of the box, the username is available through:

const os = require ('os');
const username = os.userInfo ().username;

Also (at least on Mac OS X and Linux) it can be obtained through the LOGNAME or USER environment variables:

username = process.env["LOGNAME"];
// or
username = process.env["USER"];
2

You can use the username node module ---

const username = require('username');

username().then(username => {
    console.log(username);
    //=> 'sindresorhus' 
});
charsi
  • 2,917
  • 22
  • 40
0

sync() method returns the same but without promises

document.write(username.sync());
Lyzard Kyng
  • 1,518
  • 1
  • 9
  • 14