TypeError: Cannot read property 'length' of undefined?
<p>I am getting the "TypeError: Cannot read property 'length' of undefined?" error, when I try to fetch a particular contact (provided a phone number) from my contacts saved in a file.</p>

<pre><code>exports.query = function(number) {
   var json_result = JSON.parse(read_json_file());
   console.log(json_result);
   var result = json_result.result;
   for (var i = 0; i &lt; result.length; i++) {
      var contact = result[i];
      if (contact.primarycontactnumber === number)    {
         return contact;
      }
   }
   return null;
};
</code></pre>

<p>I am calling the above code as:</p>

<pre><code>  app.get('/contacts/:number', function(request, response) {
   response.setHeader('content-type', 'application/json');
   response.end(JSON.stringify(contacts.query(request.params.number)));
 });
</code></pre>

<p>The code of my read_json_file method is:</p>

<pre><code>function read_json_file() {
   var file = './data/contacts.json';
   return fs.readFileSync(file);
}
</code></pre>