7

At this time, fs.chown requires int values for uid and gid.

So, what is the recommended way to get these int values from a UNIX-like system?

Should I read /etc/passwd and /etc/group directly?
That does not seem like the right way to do it...

700 Software
  • 85,281
  • 83
  • 234
  • 341
  • 1
    The answer for this is going to be OS and even distro-specific. In machines running the GNU userland, `/usr/bin/getent` is going to be the best way to get user and group info, as it will properly read from external authentication sources, for example. If you ever find yourself on a BSD or a Solaris, the answer may well be very different... – Charles Jan 23 '13 at 18:49

3 Answers3

2

You've probably solved it by now, but for future reference: the uid-number package is used by npm, so I think it can be safely assumed that it works (and it does for me).

Victor Welling
  • 1,867
  • 12
  • 14
2

Just call chown directly:

var exec = require( "child_process" ).exec;
exec( "chown user:group filename" );
Oliver Salzburg
  • 21,652
  • 20
  • 93
  • 138
0

I checked and found this: https://npmjs.org/package/getuid I haven't used it. caveat emptor.

Personally, I like looking these up in a configuration file that the user supplies :)

-daniel

Daniel
  • 7,006
  • 7
  • 43
  • 49