I'm trying to write really basic code where after a button press on an html file, a .txt file is written locally through a javascript function. Is this impossible to do? I can write to a file with just the javascript file but not when trying with both.
<!DOCTYPE html>
<html>
<head>
<title>Tic Tac Toe</title>
<script type = "text/javascript" src="test.js"></script>
</head>
<body>
<input type="button" onclick="javascript: myFunction()" value="Display"/>
</body>
</html>
function myFunction() {
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;
})
}
test.js