Node.js http request inside loop

I am trying to periodically load some data from external API like this:

setInterval(function() {
  getData();
}, 60000);

function getData() {
  if (typeof someObject.data === 'object') {
    for (var prop in someObject.data) {
      if (prop === 1 || prop === 2) {
        var options = {
          host: 'somehost.com',
          path: '/somepath?param=' + prop
        };
        var req = http.request(options, function(res) {
          // EXECUTION NEVER REACHES THIS POINT ?!?!
          req.on('end', function() { alert('ended'); });
        });
        req.end();
      }
    }
  }
}

If I do not do any intervals and loops, such request to the same host works perfectly. However, if I try to do something like shown above, then the request never ever calls its callback function.

What I am doing wrong here?

I think one of your conditions are bad, the following works fine for me.

var http = require('http');

setInterval(function() {
  getData();
}, 1000);

function getData() {
  console.log('get');
  //if (typeof someObject.data === 'object') {
    console.log('get 1');
    //for (var prop in someObject.data) {
      console.log('get 2');
      //if (prop === 1 || prop === 2) {
        console.log('get 3');
        var options = {
          host: 'google.com',
          path: '/'
        };
        var req = http.request(options, function(res) {
          console.log('http request', res.statusCode);
          //req.on('end', function() { 
          //  console.log('ended', req); 
          //});
        });
        req.end();
      //}
    //}
  //}
}

also If I'm right, you don't need req.on('end'), the callback of the request is called when it's completed. You can also use http.get, so you don't need to call req.end

    var req = http.get( options.host, function(res) {
      console.log('http request', res.statusCode);
      //req.on('end', function() { 
      //  console.log('ended', req); 
      //});
    }).on('error', function( e ) {
      console.error( 'error', e );
    }) 

see more info in the docs

hope I could help.