title: Node.js: How to use kafka-node for fetching messages from beginning from a topic?
body: <p>I followed <a href="https://www.digitalocean.com/community/tutorials/how-to-install-apache-kafka-on-ubuntu-14-04" rel="nofollow">this tutorial</a> for installing Kafka on Ubuntu 14.04 server. The examples provided for producer and consumer are working fine.</p>
  
  <p>Here is the producer command:</p>
  
  <pre><code>echo "Hello, World" | ~/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TutorialTopic &gt; /dev/null
  </code></pre>
  
  <p>And here is the consumer command:</p>
  
  <pre><code>~/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic TutorialTopic --from-beginning
  </code></pre>
  
  <p>However, I am trying to write a similar consumer in Node.js and it does not display the messages that existed in the topic before the consumer was created. Here is my code. What additional config is required to accomplish what I am trying ?</p>
  
  <pre><code>var kafka = require('kafka-node')
  var Consumer = kafka.Consumer
  var client = new kafka.Client("localhost:2181/")
  var consumer = new Consumer(
      client,
      [
        { topic: 'TutorialTopic', partition: 0, offset: 0}
      ],
      {
        fromOffset: true
      }
    );
  
  
  consumer.on('message', function (message) {
    console.log("received message", message);
  });
  </code></pre>