VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-fspromises-lchmod-method/

⇱ Node.js fsPromises.lchmod() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js fsPromises.lchmod() Method

Last Updated : 8 Oct, 2021

The fsPromises.lchmod() method is used to change the permissions of a given path. These permissions can be specified using string constants or octal numbers that correspond to their respective file modes.

Note: This method is only implemented on macOS. It changes the permissions of a file then resolves the Promise with no arguments upon success.

Syntax:

fsPromises.lchmod( path, mode)

Parameters: This method accepts two parameters as mentioned above and described below:

  • path: It is a string, Buffer or URL that denotes the path of the file of which the permission has to be changed.
  • mode: It is an octal integer constant that denotes the permission to be granted. The logical OR operator can be used to separate multiple permissions.
Example: This example illustrates the fsPromises.lchmod() method in Node.js: Create an "example.txt" file for granting the permission to read to the user. Filename: index.js Step to run this program: Run index.js file using the following command:
node index.js

Output:

File permission changed to read only!
EPERM
Reference: https://nodejs.org/api/fs.html#fs_fspromises_lchmod_path_mode
Comment
Article Tags:

Explore