I'm writing a NodeJS app using JS and fs to manage the filesystem. I'm using compile and resolve-to-string to replace template strings with config values. The result of that ends up in content. I'm on a Mac. Not sure that matters.
Then I have this:
try {
fs.writeFileSync(destFileName, content, 'utf8')
fs.appendFileSync(destFileName, '\r', 'utf8')
} catch (e) {
console.error(e)
}
content is a string and is written out to the .json file just fine. I can't for the life of me figure out how to add a newline to the end of the file. I've tried as many combos of \r and \n as I can think of. I've tried a few different fs file options. I've tried with and without utf8. I assume it's something super small and silly but I can't see it. :(
Following aRvi's comment, I tried adding several \n's to content and then console.loging it. All the extra newlines show up just fine in the console. Then I tried writing content to a .txt file. Extra newlines show up fine there too. Then I tried renaming .txt to a .json file and the newlines disappeared. Must be something to do with file format/extension.