+ 1
How do I change any file with any format's data or its text to same as the variable in js
How do I change any file with any format's data or its text to same as the variable in js For example text.txt = random text1 Variable = random text2 Than Text.txt = random text2
1 Antwort
+ 2
const fs = require("fs");
const filePath = "/some/path/file.txt";
const newContent = "Hello world!";
fs.readFile(filePath, "utf8", function (err, data) {
if (err) { throw err; }
console.log(data);
fs.writeFile(filePath, newContent, function(err) {
if (err) { throw err; }
});
});