Skip to content

Instantly share code, notes, and snippets.

@theptrk theptrk/save-file.js
Created Jan 19, 2019

What would you like to do?
const fs = require('fs')
const path = require('path')
const saveToFile = (entry) => {
const target = path.join(__dirname, 'did.txt')
console.log(`... 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
You can’t perform that action at this time.