The fs.fchmodSync() method is an inbuilt application programming of fs module which is used to synchronously change the permissions of a given file descriptor. These permissions can be specified as a parameter using string constants or octal numbers that corresponding to their respective file modes.
Note: The Windows platform only supports the changing of the write permission. It also does not support the distinction between the permissions of user, group, or others.
fs.fchmodSync( fd, mode )
Parameters: This method accepts two parameters as mentioned above and described below:
- fd: It is an integer which denotes the file descriptor of the file of which the permission has to be changed.
- mode: It is string constant or octal constant that denotes the permission to be granted. The logical OR operator can be used to separate multiple permissions.
Below examples illustrate the fs.fchmodSync method in Node.js:
Example 1: This example shows the usage of string constants and OR operator to give the file permissions.
Giving only read permission to user Current File Mode: 33024 File Contents: Hello World Trying to write to file Error Found, Code: EACCES Giving both read and write permission to user Current File Mode: 33152 Trying to write to file File Contents: This file has been written over.
Example 2: This example shows the usage of octal constants to give the file permissions.
Giving only read permission to everyone Current File Mode: 33060 File Contents: Hello World Trying to write to file Error Found, Code: EACCES Giving both read and write permission to everyone Current File Mode: 33206 Trying to write to file File Contents: This file has been written over.
- Nodejs | Automatic restart NodeJs server with nodemon
- Nodejs console.timeLog() Method
- Nodejs - Connect MongoDB with Node app using MongooseJS
- Cowsay in Nodejs using Requests library
- Nodejs | Web Crawling using Cheerio
- Web-Socket in NodeJS
- Signup Form Using Nodejs and MongoDB
- Dockerizing a simple Nodejs app
- Nodejs | DNS
- Encrypting Data in NodeJS
- Difference between NodeJS and AngularJS
- Nodejs | Jimp
- Nodejs – Connect Mysql with Node app
- Nodejs | DNS | setServers()
- NodeJS | Building simple REST API in express
- NodeJs - Handling invalid routes
- Nodejs | authentication using Passportjs and passport-local-mongoose
- Nodejs | GM charcoal() Function
- Nodejs | GM blur() Function
- Nodejs | GM sharpen() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nidhi_biet