CordlessWool
CordlessWool

Reputation: 1530

Change file owner in Node.js

I would like to change the file owner of a Node.js-written file. I think there is no way to set the owner directly during file write (or maybe there's a way not documented?). Is there a way to change the owner afterwards?

My Node.js app runs in a docker container under the root user. So all files written by Node.js are owned by root. I want to set the owner to www-data, for example. Is it possible?

Upvotes: 3

Views: 4555

Answers (1)

Paul
Paul

Reputation: 36339

You could use the fs module:

fs.chown(path, 1,1, console.log);

Though this presumes you know the uid and gid of www-data (user) and www-data (group).

Upvotes: 6

Related Questions