title: NodeJS - how to tell the nodeJS server to send not as chunked transfer? so that Ajax can receive it
body: <p>I have a data coming to NodeJS and then it needs to be served to Ajax query. but because the NodeJS is transfering it as chunked data, none of the general Javascript/JQuery ajax methods are able to capture the packet.</p>
  
  <p>How can i get the values </p>
  
  <p><strong>nodeJS:</strong></p>
  
  <pre><code>http.createServer(options, (req, res) =&gt; {
      msg = c++_to_javascript();
  
      res.writeHead(200);
      res.end(msg);
  
  }).listen(89);
  </code></pre>
  
  <p><strong>Javascript/JQuery:</strong> </p>
  
  <p>received the data as <code>transfer encoded: chunked</code> as a result no methods are able to decode the received packets in JS.</p>
  
  <p><a href="https://i.stack.imgur.com/KVYnK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KVYnK.png" alt="enter image description here"></a></p>
  
  <p>How could i solve it from NodeJS or in JS?</p>
  
  <p><strong>TRY 1: FAILED</strong></p>
  
  <pre><code>$.stream(javascript_to_c++,{
                          open:function(){
                              console.log("opened");
                          },
                          message:function(event){
                              console.log(event.data);
                              buf1 = buf1 + event.data;
                          },
                          error:function(){
                              console.log("error");
                          },
                          close:function(){
                              console.log("closed");
                          }
                      });
  </code></pre>
  
  <p><strong>TRY2 : FAILED</strong></p>
  
  <pre><code>  var test =  $.ajax({
      type: "GET",
      url: javascript_to_c++,
      async: false,
      success:function(m) {
        buf1 = buf1 + m;
      }
    }).responseText;
    console.log(test);
  </code></pre>
  
  <p><strong>TRY 3: FAILED</strong></p>
  
  <pre><code>// Define a method to parse the partial response chunk by chunk
  var last_index = 0;
  function parse(xhr) {
    var curr_index = xhr.responseText.length;
    if (last_index == curr_index) return; // No new data
    var s = xhr.responseText.substring(last_index, curr_index);
    last_index = curr_index;
    console.log(s);
  }
  
  function test() {
  
    var xhr = new XMLHttpRequest();
  
    var url = javascript_to_c++;
  
    xhr.open("GET", url, true); 
    xhr.send();
  
    // Check for new content every 5 seconds
    var interval = setInterval(parse, 5000);
  
    // Abort after 25 seconds
    setTimeout(function(){
      clearInterval(interval);
      parse(xhr);
      xhr.abort();
    }, 25000);
  
  }
  
  test();
  </code></pre>