Failed to lookup view "home" in view directory using handlebars

0

Hi, I'm using node with express and handlebars but when I try to render the view, the error mentioned appears.

  

Error: Failed to lookup view "home" in views directory   "/ home / joaquin / workspace / nodejs / EasyRcu / views" at   EventEmitter.render   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/application.js:579:17)   at ServerResponse.render   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/response.js:960:7)   at index   (/home/joaquin/workspace/nodejs/EasyRcu/controllers/home.js:15:17)
  at e   (/home/joaquin/workspace/nodejs/EasyRcu/controllers/index.js:17:13)
  at Layer.handle [as handle_request]   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/layer.js:95:5)   at next   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/route.js:131:13)   at Route.dispatch   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/route.js:112:3)   at Layer.handle [as handle_request]   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/layer.js:95:5)   at   /home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/index.js:277:22   at Function.process_params   (/home/joaquin/workspace/nodejs/EasyRcu/node_modules/express/lib/router/index.js:330:12)

This is my code:

app.use(express.static(__dirname + '/public'));
    app.engine('.hbs', exphbs({ defaultLayout: 'main', extname: '.hbs' }));
    app.set('views', path.join(__dirname, '/views'));
    app.set('view engine', '.hbs');

And the request Handler:

index: (req, res,next)=>{
    console.log("entre");
    var markup = react_render.renderToString(index());
    console.log(markup);
    res.render('home', {
        markup: markup,
        state : {}
    });
}
    
asked by Joaquin Noé 18.10.2016 в 15:09
source

1 answer

1

You are changing the extension with which the view engine searches for the files in the views folder.

If you write something like

res.render('home', .....

The view engine looks for home.hbs in the views folder, in your case /views

path.join(__dirname, '/views')

If you have home.handlebars it is not the same file, hence the error.

    
answered by 18.10.2016 в 16:00