+ 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

15th Oct 2022, 6:04 AM
heaker Gamer
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; } }); });
16th Oct 2022, 8:39 AM
Matthew James
Matthew James - avatar