I just want to take out the http response of "res.on("end", function...". "Dati" is always "undefined". Why?
I even tried returning the result of every function but nothing, can anyone help me out please? Thanks a lot
var dati;
function accesso() {
  var http = require("http");
  var options = {
    "method": "POST",
    "hostname": "xxx.xxx.xxx.xxx",
    "port": "xx",
    "path": "/",
    "headers": {"
    }
  };
  var req = http.request(options, function (res) {
    var chunks = [];
    res.on("data", function (chunk) {
      chunks.push(chunk);
    });
    res.on("end", function () {
      var body = Buffer.concat(chunks);
      var response = body.toString()
      obj = JSON.parse(response)
      dati = obj.session
    });
  });
  req.write("{xxxxxxxxxx}");
  req.end();
}
