Created
May 2, 2018 15:52
-
-
Save bennycode/1e4bb06dfad0aba8adc292ff29348157 to your computer and use it in GitHub Desktop.
Node.js: Append text to file
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
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