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?
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?
Share Improve this question edited Sep 20, 2017 at 8:05 Rajan Mishra 1,1782 gold badges15 silver badges31 bronze badges asked Sep 20, 2017 at 7:51 Jordy DeweerJordy Deweer 3412 gold badges4 silver badges16 bronze badges 1- 5 Possible duplicate of Find OS username in NodeJS – Serge K. Commented Sep 20, 2017 at 7:55
3 Answers
Reset to default 15Out 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"];
You can use the username node module ---
const username = require('username');
username().then(username => {
console.log(username);
//=> 'sindresorhus'
});
sync()
method returns the same but without promises
document.write(username.sync());