Skip to content
Snippets Groups Projects
Commit 626f49e7 authored by Harshith Karkera's avatar Harshith Karkera
Browse files

file create function added

parent ae2cfff7
Branches master
No related tags found
No related merge requests found
// Creating a Promise
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Hello World");
}, 1000); // Simulating an async operation with setTimeout
}, 1000);
});
// Calling the Promise
myPromise
.then((message) => {
console.log("Message:", message); // Display the message
console.log("Message:", message);
})
.catch((error) => {
console.error("Error:", error);
});
const fs = require('fs/promises');
async function createFile() {
try {
const message = "New File Created";
await fs.writeFile("message.txt", message);
console.log("File 'message.txt' has been created successfully.");
} catch (error) {
console.error("Error creating file:", error);
}
}
createFile();
New File Created
\ 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