![]() |
VOOZH | about |
The filehandle.read() method reads the file using a file descriptor. In order to read files without file descriptors the readFile() method of the filehandle package can be used. Node.js is used for server-side scripting. Reading and writing files are the two most important operations that are performed in any application. Node.js offers a wide range of inbuilt functionalities to perform read and write operations. The fs package contains the functions required for file operations.
Syntax:
filehandle.read( buffer, offset, length, position );
Parameters: This function accepts four parameters as mentioned above and described below:
Return value: It returns the Promise.
Note: "GFG.txt" should be present in the directory with the following text:
GeeksforGeeks - A computer science portal for geeks
Example: In this example, we will see the use of filehandle.read() method
Run the app.js file using the following command:
node app.js
Output:
GeeksforGeeks - A computer science portal for geeks