Created
February 14, 2018 14:30
-
-
Save seancrater/9d6ae5fd51fc6d4a9a2e12ddce1d8c3a to your computer and use it in GitHub Desktop.
Simple Node.js File Duplication Script
This file contains hidden or 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
// 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