How do I write something in a .txt file using javascript?
I created a variable holding a specific value and now I want to safe it into a .txt file
How do I write something in a .txt file using javascript?
I created a variable holding a specific value and now I want to safe it into a .txt file
You can't do this in the browser, but in node.js you can do:
var fs = require('fs');
fs.writeFile("/tmp/test.txt", yourVariable, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
Front end languages like JavaScript will not allow you to edit a file like that, for security reasons. However, you should look into Node.js file writer if you really need to write text; it allows you to write in JS but compiles into a C language (I don't remember which one). But this would mean you would need to use a node server, which might not be desired in your case.