username of current process

5,303 views
Skip to first unread message

Robbie Clutton

unread,
Sep 23, 2010, 5:32:26 AM9/23/10
to nodejs
Hi,

From the process global I can see that I can get the current user id,
but is there a way to get the current username?

Thanks

Robbie

mscdex

unread,
Sep 23, 2010, 7:24:05 AM9/23/10
to nodejs
On Sep 23, 5:32 am, Robbie Clutton <robert.clut...@gmail.com> wrote:
> Hi,
>
> From the process global I can see that I can get the current user id,
> but is there a way to get the current username?

Nothing built-in, but you could easily execute 'whoami' as a child
process.

Christian Eager

unread,
Sep 23, 2010, 7:26:41 AM9/23/10
to nod...@googlegroups.com
I'm not sure it will always be set, but would process.ENV['USER'] be
what you're looking for?

Robbie Clutton

unread,
Sep 23, 2010, 8:05:17 AM9/23/10
to nodejs
Thanks, I think I'll go for process.ENV way

Robbie

Micheil Smith

unread,
Sep 23, 2010, 9:00:51 AM9/23/10
to nod...@googlegroups.com
There could be a way. I do have a still uncompleted patch that will give access to
getting user / group info based on uid, username, gid, groupname.

Although, that patch isn't finished.

Yours,
Micheil Smith
--
BrandedCode.com

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>

Jonas Pfenniger (zimbatm)

unread,
Sep 23, 2010, 9:19:50 AM9/23/10
to nod...@googlegroups.com
I would write a small parser for /etc/passwd. This is a good learning project btw.

Narender S

unread,
Jan 20, 2015, 12:02:53 PM1/20/15
to nod...@googlegroups.com, cea...@gmail.com

Hi, 

Have you get, how to get client ID in node webserver code ? 

Ken Demarest

unread,
May 28, 2015, 8:44:41 PM5/28/15
to nod...@googlegroups.com
As of nodejs v12+ you can do this both synchronously and async on Linux, with:

process.getusername = function() {
var username =  require('child_process').execSync( "whoami", { encoding: 'utf8', timeout: 1000 } );
return String(username).trim();
}

Be warned that this is the synchronous example, so bad for web servers!

Sindre Sorhus

unread,
May 30, 2015, 5:42:11 PM5/30/15
to nod...@googlegroups.com
I have a module for that: https://github.com/sindresorhus/username
Reply all
Reply to author
Forward
0 new messages