How to make a GET call by executing a javascript file and print response in terminal
Question: So I am using python for all needs in my life and have never touched
javascript. Now I might need to learn javascript because of certain reasons.

First thing that came to my mind is to try to make a GET call and print the
response body. I seem to have trouble finding the answer for this questions.

I want to have a javascript file called `get.js`. Then I want to run the file
by `node get.js` and print the response body to terminal.

I basically want this translated from python to javascript:

Python script:

    
    
    import requests
    
    r = requests.get("http://ip.jsontest.com/")
    
    print r.text
    

In terminal:

    
    
    $ python get.py
    {"ip": "80.147.208.248"}
    


Answer: So this seems to be the way. I needed to search for "node get request" not
"javascript get request".

    
    
    var http = require('http');
    
    var options = {
      host: 'ip.jsontest.com',
      path: '/'
    };
    
    callback = function(response) {
      var str = '';
    
      response.on('data', function (chunk) {
        str += chunk;
      });
    
      response.on('end', function () {
        console.log(str);
      });
    }
    
    http.request(options, callback).end();
    

