Based on: https://stackoverflow.com/a/14181136/3363138 I did the corresponded modifications:
var fs = require('fs')
var desired_code = '<div>Desired Code</div>'
fs.readFile(file.html, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
//Here I need to load all the body tag content, but how?
var result = data.replace(<body>html tags to be replaced</body>, desired_code);
fs.writeFile(file.html, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
On this function I need to load all the body tag content, but how can I do it?
var result = data.replace(<body>html tags to be replaced</body>, desired_code);