title: Nodejs request - Cannot read property 'forEach' of undefined
body: <p>I'm following a headless Drupal tutorial at <a href="http://blog.openlucius.com/en/blog/headless-drupal-nodejs-part-33-express-js-and-drupal-api-integration" rel="nofollow">http://blog.openlucius.com/en/blog/headless-drupal-nodejs-part-33-express-js-and-drupal-api-integration</a> but my experience is with the Drupal side rather than the Node side so now that something is broken I'm not sure how to fix.</p>
  
  <p>When starting the app I get an error:</p>
  
  <pre><code>/Library/WebServer/Documents/uno-fe/hellotest.js:23
  blogsdata_all.blogs.forEach(function(item){
                     ^
  
  TypeError: Cannot read property 'forEach' of undefined
      at Request._callback (/Library/WebServer/Documents/uno-fe/hellotest.js:23:24)
      at Request.self.callback (/Library/WebServer/Documents/uno-fe/node_modules/request/request.js:200:22)
      at emitTwo (events.js:87:13)
      at Request.emit (events.js:172:7)
      at Request.&lt;anonymous&gt; (/Library/WebServer/Documents/uno-fe/node_modules/request/request.js:1067:10)
      at emitOne (events.js:82:20)
      at Request.emit (events.js:169:7)
      at IncomingMessage.&lt;anonymous&gt; (/Library/WebServer/Documents/uno-fe/node_modules/request/request.js:988:12)
  at emitNone (events.js:72:20)
  at IncomingMessage.emit (events.js:166:7)
  </code></pre>
  
  <p>my hellotest.js looks like:</p>
  
  <pre><code>var express = require('express');
  var app = express();
  var routes = require('./routes/index');
  var request = require('request');
  var blogsurlall = "http://www.pickingorganic.org/blogsexportall";
  
  app.set('view engine','ejs');
  
  var server = app.listen (2000, function(){
     console.log('Waiting for you on port 2000');
  });
  
  request({
    url:blogsurlall,
    json:true
  }, function(error, response, body){
    if (!error &amp;&amp; response.statusCode===200) {
        blogsdata_all = body;
    }
  
    var blogs = [];
  
  blogsdata_all.blogs.forEach(function(item){
      blogs = blogs.concat(item);
  });
  
    app.locals.blogsdata = blogs;
  })
  
  app.use('/', routes);
  </code></pre>
  
  <p>I'm assuming this is something to do with the node request not fetching the json from the 'source' site correctly which is why blogs var is empty.  Not sure what is going wrong tho - any help much appreciated!</p>