title: In NodeJS, how do you print lines to a file without manually adding the new line character?
body: <p>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.</p>
  
  <p>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 <code>'\n'</code> to the string.</p>
  
  <p>Here's the code I tried:</p>
  
  <pre><code>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');
  </code></pre>
  
  <p>However, the output file <code>test.out.txt</code> contains the following line with no newline characters:</p>
  
  <pre><code>line 1line 2line 3end
  </code></pre>
  
  <p>I would like it to look like this:</p>
  
  <pre><code>line 1
  line 2
  line 3
  end
  </code></pre>
  
  <p>Note that I'm not trying to log messages, and I'm not trying to redirect standard output.</p>
  
  <p>Is there any way to print it this way with the new line characters automatically added?</p>