Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created May 2, 2018 15:52
Show Gist options
  • Save bennycode/1e4bb06dfad0aba8adc292ff29348157 to your computer and use it in GitHub Desktop.
Save bennycode/1e4bb06dfad0aba8adc292ff29348157 to your computer and use it in GitHub Desktop.
Node.js: Append text to file
const os = require('os');
const fs = require('fs-extra');
const file = 'logfile.txt';
const options = {flag: 'a'};
async function writeToFile(text) {
await fs.outputFile(file, `${text}${os.EOL}`, options);
}
writeToFile('First line');
writeToFile('Second line');
writeToFile('Third line');
writeToFile('Fourth line');
writeToFile('Fifth line');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment