Skip to content

Instantly share code, notes, and snippets.

@codejockie
Last active October 17, 2017 19:14
Show Gist options
  • Select an option

  • Save codejockie/29424714af1096bcf1a440ee4c451fd1 to your computer and use it in GitHub Desktop.

Select an option

Save codejockie/29424714af1096bcf1a440ee4c451fd1 to your computer and use it in GitHub Desktop.
write/append to file
import fs from 'fs';
const file = file.txt;
fs.writeFile(file,'Some text to write.', (error) => {
if(error) {
console.error(error);
}
console.log('Written!');
});
fs.appendFile(file,'Some more text to append.', (error) => {
if(error) {
console.error(error);
}
console.log('Appended!');
});
fs.appendFile('log.txt', 'new data', (error) => {
if (error) {
// Failed: append error
} else {
// Success: append success
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment