Here is the simple chunk of code to replace a particular section in a file asynchronously.

fs.readFile(filePath, 'utf8', function(err, data) {  
    if (err) {
      return console.log(err);
    }

    var result = data.replace(your-regex-or-text,replacement-text);
    fs.writeFile(filePath, result, 'utf8', function(err) {
        if (err) {
           return console.log(err);
        };
    });
});

© 2016. All Rights Reserved.

Proudly published with Ghost