title: Using handlebars in Cloud Functions for Firebase
body: <p>I am trying to develop a prototype using Firebase. </p>
  
  <p>I am using Firebase function. My package.json file in function directory is:</p>
  
  <pre><code>{
    "name": "functions",
    "description": "Cloud Functions for Firebase",
    "dependencies": {
      "express": "^4.15.4",
      "firebase-admin": "~4.2.1",
      "firebase-functions": "^0.5.7",
      "hbs": "^4.0.1"
    },
    "private": true
  }
  </code></pre>
  
  <p>My index.js file looks like:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const express = require('express');
  const hbs = require('hbs');
  
  var app = express();
  app.set('view engine', hbs);
  
  const admin = require('firebase-admin');
  
  admin.initializeApp(functions.config().firebase);
  
  exports.getMessages = functions.https.onRequest((req, res) =&gt; {
      var abc = admin.database().ref('/messages').on("value", function(snapshot) {
          res.send(snapshot.val());
        }, function (errorObject) {
          console.log("The read failed: " + errorObject.code);
        });
  
    });
  
    exports.showMessage = functions.https.onRequest((req, res) =&gt; {
      res.render('about.hbs' , {
        pageTitle : 'About Page',
        currentYear  : new Date().getFullYear()
      });
    });
  </code></pre>
  
  <p>While "getMessage" function works fine, I get an error while executing "showMessage" function which uses third party module HBS.</p>
  
  <p>Function Logs show </p>
  
  <pre><code>Error: Cannot find module 'hbs'
      at Function.Module._resolveFilename (module.js:469:15)
      at Function.Module._load (module.js:417:25)
      at Module.require (module.js:497:17)
      at require (internal/module.js:20:19)
      at new View (/var/tmp/worker/node_modules/express/lib/view.js:50:49)
      at EventEmitter.app.render (/var/tmp/worker/node_modules/express/lib/application.js:545:12)
      at ServerResponse.res.render (/var/tmp/worker/node_modules/express/lib/response.js:938:7)
      at exports.showMessage.functions.https.onRequest (/user_code/index.js:46:9)
      at cloudFunction (/user_code/node_modules/firebase-functions/lib/providers/https.js:26:47)
      at /var/tmp/worker/worker.js:635:7
  </code></pre>