![]() |
VOOZH | about |
The fs.openSync() method is an inbuilt application programming interface of fs module which is used to return an integer value that represents the file descriptor.
Syntax:
fs.openSync( path, flags, mode )
Parameters: This method accepts three parameters as mentioned above and described below:
Return Value: It returns a number that represents the file descriptor.
The below examples illustrate the use of the fs.openSync() method in Node.js:
Example 1:
Output:
23
Here, the flag 'r' indicates that the file is already created and it reads the created file.
Example 2:
Output:
Program done! closing file now
Here, the flag 'w' indicates that the file is created or overwritten.
Reference: https://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode