Error: Failed to lookup view “./index” in views directory “/app/templates/views”

my app is working fine in local machine but when i am deploying it to production it give ‘internal server error’ on the website

src/app.js –>

const path = require('path');
const express = require('express');
const hbs = require('hbs');

// const require = require('require');
const geocode = require('./util/geocode');
const forecast = require('./util/forecast');


const app = express();

const port = process.env.PORT || 3000

console.log("xxxxxxxxxxxxxxxxxx",port)

app.listen(port);


//using public directory to load static path
const publicPath = path.join(__dirname,'../public');
app.use(express.static(publicPath));

// app.get('', (req,res)=>{

//     res.send('Hello Express')
// })

app.get('/weather', (req,res)=>{

if(!req.query.address){
   return res.send({
        error:'Please provide different address'
    })
}
geocode(req.query.address,
        (error,data)=>{
            if(error){
               return res.send({
                error:'Please provide different address'

               })

            }
            geoData = data;
            forecast(data.latitude, data.longitude, 

                (error,data)=>{
                    if(error){
                        return res.send({
                            error:'Please provide different address'
            
                           })
            

                    }
                    res.send(
                       {[ req.query.address]:{
                            searchedlocation: req.query.address,
                            location: geoData.location,
                             weather: data
                        }
}
                    
                       
                    )
                   
                   
                    }
                
                )
        
             
            
            }
        );





   
})


//using view directory of templates
const viewsPath = path.join(__dirname,'../templates/views');
app.set('view engine', 'hbs')
app.set('views', viewsPath)

app.get('/about', (req,res)=>{
    res.render('./about')
})

app.get('/', (req,res)=>{
    res.render('./index')
})

app.get('/help', (req,res)=>{
    res.render('./help')
})






//using partials directory of templates directory for dynamic view

const partialPath = path.join(__dirname,'../templates/partials')
hbs.registerPartials(partialPath);

Author: Fantashit

1 thought on “Error: Failed to lookup view “./index” in views directory “/app/templates/views”

  1. Hi

    Can you please tell me ….on how did you solved the above error, please
    Even I’m facing the same issue while deploying my app in Heroku

Comments are closed.