2017-09-20 3 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

가능한 [[OS 사용자 이름 찾기] deJS] (https://stackoverflow.com/questions/40424298/find-os-username-in-nodejs) –

답변

1

는 사용자 이름이를 통해 사용할 수 있습니다 또한

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

(적어도 맥 OS X 및 Linux) LOGNAME 또는 USER 환경 변수를 통해 얻을 수 있습니다.

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

이것은 사용자 이름이 아닌 사용자의 이름을 반환합니다. – charsi

1

당신은 username 노드 모듈을 사용할 수 있습니다 --- 박스 아웃

const username = require('username'); 

username().then(username => { 
    console.log(username); 
    //=> 'sindresorhus' 
}); 
관련 문제