#nodejs
#web development

Generate txt file using nodejs

Anonymous

AnonymousOct 12, 2023

Generate txt file using nodejs

Here's a basic Node.js script that generates single Txt file:

const fs = require('fs');

// Define the file path and content
const filePath = 'example.txt';
const fileContent = 'This is the content of the text file.';

// Write to the file
fs.writeFile(filePath, fileContent, (err) => {
  if (err) {
    console.error('Error writing to the file:', err);
  } else {
    console.log('File created and text written successfully.');
  }
});

Ouput: sample.txt

This is the content of the text file.

Happy Coding! ❤️