Skip to content

Instantly share code, notes, and snippets.

@seancrater
Created February 14, 2018 14:30
Show Gist options
  • Save seancrater/9d6ae5fd51fc6d4a9a2e12ddce1d8c3a to your computer and use it in GitHub Desktop.
Save seancrater/9d6ae5fd51fc6d4a9a2e12ddce1d8c3a to your computer and use it in GitHub Desktop.
Simple Node.js File Duplication Script
// Takes in two flags in when running the terminal process
// Example: INPUT=test.js OUTPUT=test2.js node duplicate_file.js
const fs = require('fs');
const { INPUT, OUTPUT } = process.env;
if(INPUT && OUTPUT) {
fs.readFile(INPUT, (err, data) => {
if (err) throw err;
fs.writeFile(OUTPUT, data.toString('utf8'), err => {
if (err) throw err;
console.log('File saved!');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment