Node.js callbacks in module are never called

My problem actually is that I was using the response body before the callback was called, which resulted in an error and therefore the callback was never called.

I am using request module, though this problem seems to happen with any callback.

If I do something like this.

var request = require('request');

module.exports.test = function ()
{
    request('http://www.google.com', function (error, response, body) {
        /**
         * This callback doesn't seem to ever be called.
         */

        console.log(body);
    });
};

And use it like.

var mytest = require('./test.js');

mytest.test();

The callback doesn't seem to ever be called.

Your code is working as expected and if you don't see any output that means some error had place which should be indicated in error argument passed to your function.

var request = require('request');
request('http://www.google.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body) // Print the google web page.
  } else {
    console.log('error: '+ response.statusCode)
  }
});