2017-09-20 12 views
1

電子アプリケーションでユーザー名を出力する方法を知っています。そのようなもの:電子メールでユーザー名を出力する

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

これは可能ですか?

+3

[Find OS username in No deJS](https://stackoverflow.com/questions/40424298/find-os-username-in-nodejs) –

答えて

1

--- usernameノードモジュールを使用することができ、ユーザ名は、を介して利用できます。

(少なくともMac OS XおよびLinuxの場合)また
const os = require ('os'); 
const username = os.userInfo().username; 

LOGNAMEまたはUSER環境変数を使用して取得できます。

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

これは、ユーザー名ではなくユーザーのファーストネームを返します。 – charsi

1

あなたはボックスのうち

const username = require('username'); 

username().then(username => { 
    console.log(username); 
    //=> 'sindresorhus' 
}); 
関連する問題