Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

index.js

Blame
  • index.js 674 B
    const fs = require('fs').promises;
    
    /// Promise method
    const displayMessage = () => {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve("Hello, this is a Promise message!");
            }, 1000);
        });
    };
    
    // 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();