title: Responding with a JSON object in Node.js (converting object/array to JSON string)
body: <p>I'm a newb to back-end code and I'm trying to create a function that will respond to me a JSON string. I currently have this from an example</p>
  
  <pre><code>function random(response) {
    console.log("Request handler 'random was called.");
    response.writeHead(200, {"Content-Type": "text/html"});
  
    response.write("random numbers that should come in the form of json");
    response.end();
  }
  </code></pre>
  
  <p>This basically just prints the string "random numbers that should come in the form of JSON". What I want this to do is respond with a JSON string of whatever numbers. Do I need to put a different content-type? should this function pass that value to another one say on the client side?</p>
  
  <p>Thanks for your help!</p>