how to use the chownsync function from fs-extra in javascript

Tags: Javascript, Nodejs, fs-extra, chown, chownSync

const fse = require('fs-extra');

try { // Change the owner of the file fse.chownSync('/path/to/file', 1000, 1000); console.log('Owner of the file has been changed'); } catch (err) { console.error(err); }

index.tsx

In the above code, we have used the `chownSync()` function from the `fs-extra` module to change the owner of a file. The function takes three arguments:

1. `path` - The file path whose owner is to be changed.
2. `uid` - The user id of the new owner (use `null` to leave unchanged).
3. `gid` - The group id of the new owner (use `null` to leave unchanged).

If the owner of the file has been successfully changed, the message `'Owner of the file has been changed'` will be outputted in the console. If any error occurs, it will be logged in the console using `console.error()`.
579 chars
9 lines

related categories

gistlibby LogSnag