title: NodeJS: Cannot read property 'length' of undefined
body: <p>When I run node app.js in nodejs, the error message shows 'Cannot read property 'length' of undefined'. I have installed all relevant libraries (e.g. request) and have looked at different relevant posts. However, the issue still persists.</p>
  
  <p>Please could you advise how I may fix it. Many thanks!</p>
  
  <p>Windows 10 Home PC
  Visual Studio Code</p>
  
  <pre><code>//app.js
  const geocode = require('./utils/geocode')
  const forecast = require('./utils/forecast')
  
  geocode('Boston', (error, data) =&gt; {
  console.log('Error', error)
  console.log('Data', data)
  forecast(data.latitude, data.longitude, (error, data) =&gt; {
      console.log('Error', error)
      console.log('Data', data)
  })
  
  
  })
  
  // forecast.js
  const request = require('request')
  
  const forecast = (latitude, longitude, callback) =&gt; {
  const url = 
  'https://api.darksky.net/forecast/9d1465c6f3bb7a6c71944bdd8548d026/' + 
  latitude + ',' + longitude
  
  request({ url: url, json: true }, (error, response) =&gt; {
      if (error) {
          callback('Unable to connect to weather service!', undefined)
      } else if (response.body.error) {
          callback('Unable to find location', undefined)
      } else {
          callback(undefined, response.body.daily.data[0].summary + ' It is 
  currently ' + response.body.currently.temperature + ' degress out. There 
  is a ' + response.body.currently.precipProbability + '% chance of rain.')
      }
  })
  }
  
  module.exports = forecast
  
  
  // geocode.js
  const request = require('request')
  
  const geocode = (address, callback) =&gt; {
  const url = 'https://api.mapbox.com/geocoding/v5/mapbox.places/' + 
  address + '.json?access_token=pk.eyJ1IjoiYW5kcmV3bWVhZDEiLCJhIjoiY2pvOG8ybW90MDFhazNxcnJ4OTYydzJlOSJ9.njY7HvaalLEVhEOIghPTlw&amp;limit=1'
  
   request({ url: url, json: true }, (error, response) =&gt; {
      if (error) {
          callback('Unable to connect to location services!', undefined)
       } else if (response.body.features.length === 0) {
          callback('Unable to find location. Try another search.', 
  undefined)
      } else {
          callback(undefined, {
              latitude: response.body.features[0].center[0],
              longitude: response.body.features[0].center[1],
              location: response.body.features[0].place_name
          })
      }
  })
  }
  
  module.exports = geocode
  </code></pre>
  
  <p>I expect to see Boston, its latitude and its longitude.</p>