var request = require('request');
var express = require("express");

var app = express();

const SERVER_PORT = 3000;


app.get("/test", function(req, res) {
  var data = "";
  res.oldWriteHead = res.writeHead;
  contentLength = 50;

  data += "1\n";
  data += "100\n";
  data += "2\n";


  request(
    'https://newsapi.org/v1/articles?source=the-hindu&sortBy=top&apiKey=21ea495f516d47f78e356d7c1641d7ed',
    function(error, response, body) {
      if (!error && response.statusCode == 200) {
        var feeddata = JSON.parse(body);
        for (i in feeddata.articles) {
          entry = feeddata.articles[i];
          console.log(entry.title, entry.description);

          //strip all , to ;
          entry.description = entry.description.replace(",", ";");

          entry.description = entry.description.toUpperCase();

          data += "1000\n" + entry.description.length + "\n" + entry.description +
            "\n";
          console.log(data);
        }
        res.header('Content-Type', 'text/plain');
        // res.write(data);
        res.send(data);
      }
    });



})


console.log("Application started  at port ", SERVER_PORT);

app.listen(SERVER_PORT);

@@ -111,16 +111,465 @@
  3000;%0A%0A
+function toASCII(chars) %7B%0A  var ascii = '';%0A  for (var i = 0, l = chars.length; i %3C l; i++) %7B%0A    var c = chars%5Bi%5D.charCodeAt(0);%0A    if (chars%5Bi%5D == %22%E2%80%99%22) %7B%0A      ascii += %22'%22;%0A    %7D else if (chars%5Bi%5D == %22%E2%80%9D%22) %7B%0A      ascii += %22%5C%22%22;%0A    %7D else if (chars%5Bi%5D == %22%E2%80%9C%22) %7B%0A      ascii += %22%5C%22%22;%0A    %7D else %7B%0A      if (c %3E= 0xFF00 && c %3C= 0xFFEF) %7B%0A        c = 0xFF & (c + 0x20);%0A      %7D%0A%0A      ascii += String.fromCharCode(c);%0A    %7D%0A  %7D%0A%0A  return ascii;%0A%7D%0A%0A
 %0Aapp.get
@@ -1331,24 +1331,47 @@
 gth + %22%5Cn%22 +
+ toASCII(%0A             
  entry.descr
@@ -1376,16 +1376,17 @@
 cription
+)
  +%0A     

fix utf8 issue