Skip to content

Instantly share code, notes, and snippets.

@asduser
Created January 12, 2017 22:20
Show Gist options
  • Save asduser/e759b620cbbe83c01a62b6c05f7733ba to your computer and use it in GitHub Desktop.
Save asduser/e759b620cbbe83c01a62b6c05f7733ba to your computer and use it in GitHub Desktop.
Node.js snippets #1
function copySync(src, dest) {
if (!fs.existsSync(src)) return false;
var data = fs.readFileSync(src, 'utf-8');
fs.writeFileSync(dest, data);
}
function replaceInFile(src, replaceKey){
fs.readFile(src, 'utf8', function (err, data) {
if (err) return console.log(err);
console.log(data);
var result = data.replace(/_CFG_PATH_/g, replaceKey);
fs.writeFile(src, 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