Skip to content

Instantly share code, notes, and snippets.

@bmnepali
Created March 6, 2019 11:07
Show Gist options
  • Save bmnepali/5b6076e87e430641cff36c53c77e37bc to your computer and use it in GitHub Desktop.
Save bmnepali/5b6076e87e430641cff36c53c77e37bc to your computer and use it in GitHub Desktop.
Replace desired string in the file using the nodejs
var fs = require('fs')
fs.readFile(someFile, 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
var result = data.replace(/string to be replaced/g, 'replacement');
fs.writeFile(someFile, result, 'utf8', function (err) {
if (err) return console.log(err);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment