The fs.accessSync() method is used to synchronously test the permissions of a given file or directory. The permissions to be checked can be specified as a parameter using file access constants. It is also possible to check multiple file permissions by using the bitwise OR operator to create a mask with more than one file constant.
fs.accessSync( path, mode )
Parameters: This method accepts two parameters as mentioned above and described below:
- path: It is a String, Buffer or URL which denotes the path of the file or directory for which the permission has to be tested.
- mode: It is an integer value that denotes the permission to be tested for. The logical OR operator can be used to separate multiple permission. It can have the values
fs.constants.X_OK. It is an optional parameter. The default value is
Below examples illustrate the fs.accessSync() method in Node.js:
Example 1: This example shows the testing of the read and write permission of a file.
Giving only read permission to user > Checking Permission for reading the file File can be read > Checking Permission for reading and writing to file No Read and Write access
Example 2: This example shows the testing of a file if it exists.
> Checking if the file exists File does not exist Creating the file > Checking if the file exists File does exist
- 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 firstname.lastname@example.org. 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