在Electron中输出用户名
我真的知道如何在Electron应用程序中输出用户名。 所以这样的事情:
const os = require('os') const username = // the code or the username so that it can be displayed document.write("The username is: " + username)
那可能吗?
开箱即用,用户名可以通过:
const os = require ('os'); const username = os.userInfo ().username;
另外(至less在Mac OS X和Linux上)可以通过LOGNAME或USER环境variables获得:
username = process.env["LOGNAME"]; // or username = process.env["USER"];
你可以使用用户名节点模块—
const username = require('username'); username().then(username => { console.log(username); //=> 'sindresorhus' });