Skip to content

Instantly share code, notes, and snippets.

@theptrk
Created January 19, 2019 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theptrk/ada41090cb7761f13f30342c7d0117ba to your computer and use it in GitHub Desktop.
Save theptrk/ada41090cb7761f13f30342c7d0117ba to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
const saveToFile = (entry) => {
const target = path.join(__dirname, 'did.txt')
console.log(chalk.green(`... saving to did.txt`))
if (fs.existsSync(target)) {
// if the file exists, we will append to the existing file
return fs.appendFileSync(target, '\n\n' + entry);
}
else {
// if the file doesn't exist, we will write to a new file
return fs.writeFileSync(target, entry);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment