Skip to content

Instantly share code, notes, and snippets.

@sabesansathananthan
Last active September 8, 2022 09:06
Show Gist options
  • Save sabesansathananthan/aa2ba85035b33757f43896da1bbe2faf to your computer and use it in GitHub Desktop.
Save sabesansathananthan/aa2ba85035b33757f43896da1bbe2faf to your computer and use it in GitHub Desktop.
How to copy files and folders in Node.js
fs.readFile('./data.txt', { encoding: 'utf8' }, (err, data) => {
if (err) {
console.error(err);
return;
}
data = data.replace(/hi/gi, 'world');
fs.writeFile('./info.txt', data, (err) => {
if (err) {
console.error(err);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment