So I've been searching for hours on this topic, and still have not found any real way to achieve what I'm trying to do here.
Simply, I just want to write some text to a text file through the use of a button in HTML. This is what I have:
<!DOCTYPE html>
<html>
<head>
<title>TEST</title>
</head>
<body>
<button onclick="write_text()">WRITE FILE</button>
<script>
function write_text(){
var fs = require('fs');
fs.writeFile("test.txt", "okay this is epic", function(err){
if (err) return console.log(err);
console.log("Nice");
});
};
</script>
</body>
</html>
I'm unsure as to why this doesn't work, do I need to make a separate .js file for the function that the button references?
Any help would be appreciated, Thanks.
EDIT: I'm trying to save the file to my GoDaddy server so that I can access it later, not just download the file. Testing it locally, it should create a file in the directory of my html document.