FSD-II Practical Assignment-10

 10.Build a small application that uses multiple modules to perform specific tasks (e.g., file manipulation, data processing).


const fs = require('fs').promises; // Using promises for better async handling 

async function main() 

{

 try 

{ // **Read from a file** 

const data = await fs.readFile('input.txt', 'utf8'); 

console.log('File content:', data); 

// **Write to a new file**

 const outputData = { message: "This is written to output1.json"}; 

await fs.writeFile('output1.json', JSON.stringify(outputData, null, 2));

 console.log('Data written to output.json'); // **Append data to an existing file** 

const additionalContent = "\nThis line is appended to input.txt."; 

await fs.appendFile('input.txt', additionalContent); 

console.log('Data appended to input.txt'); 

// **Delete a file** await fs.unlink('output1.json'); 

console.log('output1.json deleted successfully');

 } catch (error) { console.error('Error:', error);

 } 

} // Run the main function main(); 

main();






Comments

Popular posts from this blog

Slip 11: Write node js application that transfer a file as an attachment on web and enables browser to prompt the user to download file using express js.

Slip 7 Create a node js file named main.js for event-driven application. There should be a main loop that listens for events, and then triggers a callback function when one of those events is detected.

Slip 1(a) Write an Angular 13 application addition of two numbers using ng-init, ng-model & ng-bind. And also demonstrate ng-show, ng-disabled, ng-click directives on button component.