'Error: Failed to lookup view "main" in views directory "./views"
I have made the handlebars config in my index.js that I think was made correctly, but I continue to get this error where my main.hbs dont get found
Here's my code:
const express = require('express');
const mysql = require('mysql2');
const bodyParser = require('body-parser');
const { engine } = require('express-handlebars');
const app = express();
app.engine("handlebars", engine())
app.set("view engine", "handlebars")
app.set("views", "./views")
app.get('/', (req,res) => {
res.render('main')
})
app.listen(3000, () => {
console.log('Servidor na porta 3000')
})
Project structure is built this way:
.
├── index.js
└── views
├── home.handlebars
└── layouts
└── main.handlebars
Complete log error
Error: Failed to lookup view "main" in views directory "./views"
at Function.render (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\application.js:580:17)
at ServerResponse.render (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\response.js:1017:7)
at C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\index.js:13:7
at Layer.handle [as handle_request] (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:341:12)
at next (C:\Users\lopes\OneDrive\Área de Trabalho\JS\VanillaJS-Crud\node_modules\express\lib\router\index.js:275:10)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
