I'm trying to figure out how to simply write a string representing a line to a file, where whatever function I call automatically appends a newline character.
I've tried using the default NodeJS file system library for this but I can't get this to work in any way without manually appending '\n'
to the string.
Here's the code I tried:
const fs = require('fs');
const writer = fs.createWriteStream('test.out.txt', { flags: 'w' })
writer.write('line 1')
writer.write('line 2');
writer.write('line 3');
writer.end('end');
However, the output file test.out.txt
contains the following line with no newline characters:
line 1line 2line 3end
I would like it to look like this:
line 1
line 2
line 3
end
Note that I'm not trying to log messages, and I'm not trying to redirect standard output.
Is there any way to print it this way with the new line characters automatically added?