os.userInfo([options])


  • options <Object>

    • encoding <string> 用于解释结果字符串的字符编码. 如果encoding 被设置为'buffer', username, shell, 和 homedir 的值将成为 Buffer的实例. (默认是: 'utf8')
  • Returns: <Object>

os.userInfo()方法当前有效用户的信息 -- 在 POSIX平台上, 这通常是password 文件的子集. 返回的对象包括 username, uid, gid, shell, 和 homedir. 在Windows系统上, uidgid 域是 -1, and shellnull.

homedir的值由os.userInfo()返回, 由操作系统提供. 这区别了os.homedir()的结果, 它在求助操作系统响应之前, 为home目录请求几个环境变量.

  • options <Object>

    • encoding <string> Character encoding used to interpret resulting strings. If encoding is set to 'buffer', the username, shell, and homedir values will be Buffer instances. Default: 'utf8'.
  • Returns: <Object>

The os.userInfo() method returns information about the currently effective user — on POSIX platforms, this is typically a subset of the password file. The returned object includes the username, uid, gid, shell, and homedir. On Windows, the uid and gid fields are -1, and shell is null.

The value of homedir returned by os.userInfo() is provided by the operating system. This differs from the result of os.homedir(), which queries several environment variables for the home directory before falling back to the operating system response.