'Uncaught TypeError: Failed to construct 'File': 2 arguments required, but only 1 present

I am writing a JavaScript to write file to the local directory in an aframe virtual reality application using Google Chrome.

While debugging I've gotten this error:

Uncaught TypeError: Failed to construct 'File': 2 arguments required, but `only 1 present.`

I've gotten the following code from someone else and I don't understand why Google Chrome says 2 arguments are required for this?

<script>
/// write to file
var txtFile = "skycolour.txt";
var file = new File(txtFile);
var str = "My string of text";

file.open("w"); // open file with write access
file.writeln("First line of text");
file.writeln("Second line of text " + str);
file.write(str);
file.close();
</script>

Thank you for helping out.

Image of the error for your reference



Solution 1:[1]

// Requiring fs module in which 
// writeFile function is defined. 

 const fs = require('fs') 

// Data which will write in a file. 

let data = "Learning how to write in a file."

// Write data in 'Output.txt' . 

fs.writeFile('Output.txt', data, (err) => { 

   // In case of a error throw err. 

    if (err) throw err; 
}) 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chukwu3meka