How to write files in node.js?



How to write files in node.js?..

Answer / Anurag Singh Chauhan

To write a file in Node.js, use the 'writeFile' function from the 'fs' module. Here's an example:n```javascriptnconst fs = require('fs');nnconst data = 'Hello World';nnfs.writeFile('output.txt', data, (err) => {n if (err) throw err;n console.log('The file has been saved!');n});n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Node.js Interview Questions

What are node packages and how to install/uninstall them?

1 Answers  


Explain what is a javascript engine?

1 Answers  


What is a Callback function in Node.js?

1 Answers  


Using the event loop what are the tasks that should be done asynchronously?

1 Answers  


How will you close a file using node?

1 Answers  


How do callbacks work?

1 Answers  


Is node.js free to use?

1 Answers  


What is rest api in node js?

1 Answers  


How will you read a directory?

1 Answers  


What is npm? What is the main functionality of npm?

1 Answers  


What is orm in node.js?

1 Answers  


Why to use node.js?

1 Answers  


Categories