Used Function: The writeFile() functions is used for writing operations.
writeFile( Path, Data, Callback)
Parameters: This method accepts three parameters as mentioned above and described below:
- Path: It takes in the relative path from the program to the text File. If the file is to be created in the same folder as that of the program, then give the name of the file only. If the file does not exist then a new file will be created automatically.
- Data: This argument takes in data that need to write in the file.
- Callback Function: It is the callback function that further has an argument (err). If the operation fails to write the data, err shows the fault.
Learning how to write in a file.
Note: Above script can be run using the NodeJs interpreter in the terminal.