Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS: Alternative to chown string

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...

like image 925
700 Software Avatar asked Jan 23 '13 03:01

700 Software


2 Answers

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).

like image 135
Victor Welling Avatar answered Oct 03 '22 18:10

Victor Welling


Just call chown directly:

var exec = require( "child_process" ).exec;
exec( "chown user:group filename" );
like image 40
Oliver Salzburg Avatar answered Oct 03 '22 17:10

Oliver Salzburg