You're trying to stringify the result of http.createServer(...)
. That'll not be what you want to do, so when you create that property, make it non-enumerable by defining it using Object.defineProperty()
.
exports.createSlave = function (id, coordinatorK, port) {
var temp = new Slave ();
temp.ID = id;
temp.coordinator = coordinatorK;
temp.thePort = port;
Object.defineProperty(temp, "httpServer", {
value: http.createServer(handle_incoming_request),
enumerable: false, // this is actually the default, so you could remove it
configurable: true,
writeable: true
});
temp.httpServer.listen (temp.thePort);
return temp;
}
This way JSON.stringify
won't reach that property curing its enumeration of the object.