Node.Js - Get windows username

后端 未结 6 1473
臣服心动
臣服心动 2021-02-05 09:50

I am trying to get the windows username of the machine that is running my node.jS app (the app is always running on a Windows machine).

How can I get the current windows

6条回答
  •  清酒与你
    2021-02-05 10:05

    Since Node v6 (2016-04), you can just use os.userInfo :

    To get the current logged-in username:

    var path = require('path');
    var userName = process.env['USERPROFILE'].split(path.sep)[2];
    var loginId = path.join("domainName",userName);
    console.log(loginId);
    

    once we get the username from above code.we can't able to hit this username api by client side.it showing 401 res for this method

提交回复
热议问题