Parse Cloud Hosting with Express and Handlebars templates

There is a node package for using handlebars templates in Express.js, express-handlebars, but I would like to be able to use the same package in a Parse Cloud Hosting project. The only discussion I can find on how to get it to work is here, and it's excruciatingly short-lived: https://parse.com/questions/dynamic-website-handlebars-for-template-engine

The last comment mentions pointing the "cloud" directory to the required command for many dependent modules. The author doesn't explain how he did it and the stream is now closed.

After following the installation instructions, I have this in my main app.js file:

var express = require('express');
var exphbs = require('express-handlebars');

var parseExpressCookieSession = require('parse-express-cookie-session');

var home = require('cloud/routes/home');
var register = require('cloud/routes/register');
var login = require('cloud/routes/login');

var app = express();

// Configure the app
app.set('views', 'cloud/views');
app.set('view engine', 'hbs');
app.engine('hbs', exphbs({
  extname: 'hbs',
  defaultLayout: 'layouts/main.hbs'
}));

app.use(express.bodyParser());

app.use(express.methodOverride());
app.use(express.cookieParser('ABCDEFG1234567'));
app.use(parseExpressCookieSession({ cookie: { maxAge: 3600000 }}));
app.use(app.router);

// Define all the endpoints
app.get('/', home.index);
app.get('/register', register.new);
app.post('/register', register.create);
app.get('/login', login.new);
app.post('/login', login.create);
app.get('/logout', login.destroy);

app.listen();

      

My file structure looks like this:

cloud
  └──routes
  └──views
      └──layouts
          └──main.hbs
      └──home
          └──index.hbs
      └──register
          └──new.hbs
      └──login
          └──new.hbs
config
node_modules
public
package.json

      

All route files are a small change:

exports.index = function(req, res){
  res.render('home/index');
};

      

Running my application results in the following error:

Error: Failed to lookup view "home/index"

      

With the default 'ejs' templates, the app works fine. Personally, I'm fine with ejs templates, but that's not for me. Steering is what the project requires, so I have to follow through. Thank!

+3


source to share





All Articles