Used Function: The readFile() functions is used for reading operation.
readFile( Path, Options, Callback)
Parameters: This method accepts three parameters as mentioned above and described below:
- path: It takes in relative path from the program to the text File. If both file and program is in the same folder, then simply give the file name of the text file.
- Options: It is an optional parameter which specify the data is to be read from the file. If nothing is passed, then default raw buffer is returned.
- Callback Function: It is the callback function which has further two arguments (err, data). If the operation fails to extract the data, err shows what is the fault, else data argument will contain the data from the file.
- Input.txt file: This is some data inside file Input.txt.
- Instead of converting buffer into text using tostring function, directly get the data into text format also.
This is some data inside file Input.txt.
Note: To run the script first make both files in the same folder and then run script.js using NodeJs interpreter in terminal.
Please Login to comment...