view-engine
Я установил hbs вместо руля для динамических шаблонов, и теперь я застрял в этой проблеме.
Error: Failed to lookup view "index" in views directory "/home/trijay/Desktop/NodeJs/web-server/src/views"
at Function.render (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/response.js:1008:7)
at app.get (/home/trijay/Desktop/NodeJs/web-server/src/app.js:14:9)
at Layer.handle [as handle_request] (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/layer.js:95:5)
at next (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/layer.js:95:5)
at /home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/index.js:335:12)
at next (/home/trijay/Desktop/NodeJs/web-server/node_modules/express/lib/router/index.js:275:10)
Ниже приведен мой код для app.js, а также я установил библиотеку hbs, express. Будем благодарны за любую помощь
// app.js
const express = require('express')
const path = require('path')
const publicPath = path.join(__dirname, '../public') //for accessing comeplete file
const app = express() //express being initialised
app.use(express.static(publicPath))
app.set('view engine', 'hbs') //use to set handle bars. we need to provide key value pair
app.get('', (req, res) => {
res.render('index') //need to provide the hbs file name which you will find in view
})
app.get('/weather', (req, res) => {
res.send({
latitude: -57.89,
longitude: 78.42,
location : 'New Delhi'
})
})
app.listen(3000, () => {
console.log('Server Started on port 3000')
})