I want the program to stop listening for requests and continue on with the code after it has successfully loaded the page once. I have tried putting a break;
at the end of the code in the function, but it says that is an illegal break. I don't know what I should be using instead of break.
How should I be causing it to exit the function?
Thanks in advance.
I am using the following code from this site with Node.js:
var http = require("http");
var port = 3000;
var serverUrl = "localhost";
var Kafka = require('no-kafka');
var connString = ' kafka://192.168.0.108:9092, 192.168.0.108:9092 '
var consumer = new Kafka.SimpleConsumer({ connectionString: connString });
var message = ["start"];
var server = http.createServer(function(req, res) {
console.log("Request: " + req.url);
var now = new Date();
var html = "<p>Hello World, the time is " + now + "- Messages: " + message + ".</p>";
res.end(html);
console.log("a");
server.close();
console.log("b");
});
// data handler function can return a Promise
var dataHandler = function (messageSet, topic, partition) {
messageSet.forEach(function (m) {
console.log('topic received: ');
console.log({
'topic':topic,
'partition': partition,
'offset': m.offset,
'message': m.message.value.toString('utf8')
});
message.push(m.message.value.toString('utf8'));
console.log("Listening at " + serverUrl + ":" + port);
server.listen(port, serverUrl);
console.log("c");
});
};
return consumer.init()
.then(function () {
return consumer.subscribe('temp', 0, dataHandler);
});