![]() |
VOOZH | about |
The fsPromises.writeFile() method asynchronously writes data to a file and replaces the file by default, with optional settings to control its behavior.
Syntax
fsPromises.writeFile( file, data, options )utf80o666wBelow examples illustrate the fsPromises.writeFile() method in Node.js:
[Example 1]: Create and write content into movies.txt asynchronously using fsPromises.writeFile() in Node.js
Output:
File written successfully
The written file has the following contents:
This is a file containing a collection of movies.
[Example 2]: Write data to a file asynchronously using fsPromises.writeFile() in Node.js
Output:
File written successfully
The written has the following contents:
This is a file containing a collection of books.
Reference: https://nodejs.org/api/fs.html#fs_fspromises_writefile_file_data_options