title: Google Cloud Functions - nodejs6 cloud function not working in nodejs8(beta)
body: <p>My code is successfully working in nodejs6. I just wanted to deploy it in nodejs8. </p>
  
  <p>index.js contains below code</p>
  
  <pre><code>// [START functions bgMCMA]
  /**
   * Background Cloud Function - Triggered by PubSub.
   * @param {!Object} event The Cloud Functions event.
   * @param {!Function} The callback function.
   */
  exports.bgScrapeMCMA = (event, callback) =&gt; {
  
      //Logic to avoid infinite loop on timeout
      const eventAge = Date.now() - Date.parse(event.timestamp);
      const eventMaxAge = 420000; //7Minutes as timeout is set as 504 seconds(9Minutes)
  
      // Ignore events that are too old
      if (eventAge &gt; eventMaxAge) {
        console.log(`INFINITE-LOOP-BREAK : Dropping context ${context} with age ${eventAge} ms.`);
        callback(); // Don't forget to call the callback. Remember its either a callback() or promise
        return;
      }    
  
      // The Cloud Pub/Sub Message object.
      const pubSubMessage = event.data;
      const message = pubSubMessage.data ? Buffer.from(pubSubMessage.data, 'base64').toString() : 'NONE';
  
      console.log('MCMA triggered time : ' + DateTime.getCurrentISTdt("yyyy-mmm-dd hh:mm:ss") + ' Message : ' + message);
  
      MCMA.start().then( (resp) =&gt;{
          console.log('MCMA : Success : '+resp);
          callback(); // Don't forget to call the callback. Remember its either a callback() or promise        
      }).catch( (e) =&gt;{
          console.error('MCMA : Error : '+e);
          callback(); // Don't forget to call the callback. Remember its either a callback() or promise
      });
  
  };
  // [END functions bgMCMA]
  </code></pre>
  
  <p>Deployed to nodejs8 using below command</p>
  
  <pre><code>gcloud functions deploy bgScrapeMCMA --trigger-resource psTriggerbgScrapeMCMA --trigger-event google.pubsub.topic.publish --entry-point=bgScrapeMCMA --timeout=540s --runtime nodejs8
  </code></pre>
  
  <p>Function got deployed successfully.</p>
  
  <p>I am triggering the code via pubsub. From the functions console, i will click the topic and publish message like "TEST" in the message textarea.</p>
  
  <p>What expected is ?<br>
  When in check in the logs it usually displays the message "TEST". So, i can understand function is triggered successfully. </p>
  
  <p>What i am seeing after deploying in nodejs8 ?   </p>
  
  <ol>
  <li><p>After i input the message "TEST" in pubsub. In the log the message i see is "NONE". So my understanding is function got triggered by it didn't get my message.   </p></li>
  <li><p>After function executing for around 45Seconds. It crashes with message textPayload:  "Error: function crashed out of request scope
  Function invocation was interrupted.".   </p></li>
  <li><p>When i rerun the same, this time it crashes because of memory textPayload:  "Error: memory limit exceeded. Function invocation was interrupted."   </p></li>
  </ol>
  
  <p>Since the second time it crashes due to memory, currently using is 256MB. So i edit the function and increase it to 512MB. The first error comes back again, "Error: function crashed out of request scope
   Function invocation was interrupted.".   </p>
  
  <p>At this point, i doubt my program which was previously working, just to upgrade to nodejs8. I deleted the previous working function and tried to deploy it with new node version. So i go back and redeploy with nodejs6 and 256MB memory. When i execute the function it works.   </p>
  
  <p>What the function basically does is, it scrapes a site and updates firebase. Functions elapsed is around 10s - 45s.   </p>
  
  <p>So two things i would basically like to know is, what has changed in NodeJS8 in GCP.<br>
  1. Simple message from pubsub is not coming in the log  </p>
  
  <pre><code>const pubSubMessage = event.data;
  const message = pubSubMessage.data ? Buffer.from(pubSubMessage.data, 'base64').toString() : 'NONE';
  
  console.log('MCMA triggered time : ' + DateTime.getCurrentISTdt("yyyy-mmm-dd hh:mm:ss") + ' Message : ' + message);
  </code></pre>
  
  <ol start="2">
  <li>Consuming lots of memory. What working nodejs6 with 256MB is crashing with even 512MB.  </li>
  </ol>
  
  <p>I know nodejs8 is in beta. Eventually it will come to GA. How to resolve this.  </p>