nodejs put array in file

const fs = require('fs');

// Step 1: Define an array
const myArray = [1, 2, 3, 4, 5];

// Step 2: Convert the array to a string
const arrayString = JSON.stringify(myArray);

// Step 3: Specify the file path
const filePath = 'output.txt';

// Step 4: Write the stringified array to the file
fs.writeFileSync(filePath, arrayString);

// Step 5: Log a message indicating successful writing to the file
console.log('Array has been written to the file:', filePath);