You really need to use callbacks and the ->net<- library.
net library doc
var net = require('net');
var client = net.connect({port: 8124},
function() { //'connect' listener
console.log('connected to server!');
client.write('world!\r\n');
});
client.on('data', function(data) {
console.log(data.toString());
client.end();
});
client.on('end', function() {
console.log('disconnected from server');
});
I copied that example from the oficial docs, as you can see you really need to use callbacks on the events, in this case de "data" event, when you get the complete response THEN you proceed to send your response.
Your XML is incomplete because you send the response before the Socket finish to recieve the data.
Remember javascript is non-blocking, and this things can happen, thats why you need to learn how to use events and callbacks.
PLEASE use the net library.
Hope it helps.
PD: im sorry about my poor english but im trying to be helpful.