Skip to content
Snippets Groups Projects
Commit 69bac5e2 authored by Nitesh Verma's avatar Nitesh Verma
Browse files

Write file function implemented

parent 7b24ebb6
No related branches found
No related tags found
No related merge requests found
const fs = require('fs').promises;
/// Promise method
const displayMessage = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
......@@ -9,3 +12,15 @@ const displayMessage = () => {
// Calling the promise
displayMessage().then(console.log).catch(console.error);
// Creating a file using fs module
const writeFile = async () => {
try {
await fs.writeFile("message.txt", "This file was created using fs module!");
console.log("File created successfully!");
} catch (error) {
console.error("Error creating file:", error);
}
};
// Calling the write file function
writeFile();
\ No newline at end of file
This file was created using fs module!
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment