Its like this. Thank you.
var testFunc : function(stuff, callback) {
var result = {
error: false,
data: ''
};
var post_body_xml = xmlbuilder.buildObject(post_body);
// An object of options to indicate where to post to
var post_options = {
host: api.endpoint,
path: api.path,
port: '80',
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'Content-Length': post_body_xml.length
}
};
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
result.data += chunk;
});
res.on('error', function(e) {
console.log('problem with request: ' + e.message);
result = {
error: true,
data: e.message
};
});
res.on('end', function() {
xmlparser.addListener('end', function(json_result) {
result.data = json_result;
//console.log(result);
callback(result);
});
xmlparser.parseString(result.data);
});
});
// post the data
post_req.write(post_body_xml);
post_req.end();
};