1
My folders:
The "admin.js" file contains my routes:
const express = require('express')
const router = express.Router()
router.get('/', (req,res)=>{
res.render("admin/index")
})
router.get('/posts',(req,res)=>{
})
router.get('/categorias',(req,res)=>{
res.send("aaaaaaaaa")
})
module.exports = router
The file "App.js"
const express = require('express')
const handlebars = require('express-handlebars')
const bodyParcer = require('body-parser')
const app = express()
const admin = require('./routes/admin')
const path = require('path')
//const mongoose = require('mongoose')
//Body Parcer
app.use(bodyParcer.urlencoded({extended:true}))
app.use(bodyParcer.json())
//HandleBars
app.engine('handlebars', handlebars({defaultLayout: 'main'}))
app.set('view engine', 'handlebars')
//Mongoose
//Public
app.use(express.static(path.join(__dirname,"public")))
//Rotas
app.use('/admin',admin)
const PORT = 8080
app.listen(PORT,()=>console.log(`Servidor Rodando na porta ${PORT} ...`))
When I try to access the url "http://localhost:8080/admin/" to access the "index.handlebars" file in the "views/admin" folder, the following error occurs:
Error: Failed to lookup view "admin/index" in views directory "C:\workspaceN\BlogApp\views"
if you notice the image you will see that its written "index.hadlebars" and the right one would be "index.
– Jeferson Mesquita