I have server that replaces some strings in a file. It looks like this:
var stringToBeReplacedWith = "Cool text";
var data = fs.readFileSync(file, 'utf-8');
var RegExp = new RegExp("Stringtobereplaced", 'g'); // global search
data = fileContents.replace(RegExp, stringToBeReplacedWith);
fs.writeFileSync(file, data);
The code works by the Mime-type/encoding changes.
How can I make sure the Mime-Type is preserved when replacing the string? I've noticed there are plenty of libraries to read the mimetype but (so far) I haven't found a library that does the opposite.