Created
March 6, 2019 11:07
-
-
Save bmnepali/5b6076e87e430641cff36c53c77e37bc to your computer and use it in GitHub Desktop.
Replace desired string in the file using the nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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