title: Proper way to return JSON using node or Express
body: <p>So, one can attempt to fetch the following JSON object:</p>
  
  <pre><code>$ curl -i -X GET http://echo.jsontest.com/key/value/anotherKey/anotherValue
  HTTP/1.1 200 OK
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=ISO-8859-1
  Date: Wed, 30 Oct 2013 22:19:10 GMT
  Server: Google Frontend
  Cache-Control: private
  Alternate-Protocol: 80:quic,80:quic
  Transfer-Encoding: chunked
  
  {
     "anotherKey": "anotherValue",
     "key": "value"
  }
  $
  </code></pre>
  
  <p>Is there a way to produce exactly the same body in a response from a server using node or express? Clearly, one can set the headers and indicate that the content-type of the response is going to be "application/json", but then there are different ways to write/send the object. The one that I have seen commonly being used is by using a command of the form:</p>
  
  <pre><code>response.write(JSON.stringify(anObject));
  </code></pre>
  
  <p>However, this has two points where one could argue as if they were "problems":</p>
  
  <ul>
  <li>We are sending a string.</li>
  <li>Moreover, there is no new line character in the end.</li>
  </ul>
  
  <p>Another idea is to use the command:</p>
  
  <pre><code>response.send(anObject);
  </code></pre>
  
  <p>This appears to be sending a JSON object based on the output of curl similar to the first example above. However, there is no new line character in the end of the body when curl is again being used on a terminal. So, how can one actually write down something like this with a new line character appended in the end using node or node/express?</p>