express.handlebars not routing properly

252 views Asked by At

I am attempting to access the home route using the express.handlebars method

via https://www.npmjs.com/package/express-handlebars

I'm using VSC instead of Atom. Mind overload.

Here's my explorer.

my index.js file

    const express = require('express');
    const app = express();
    const exphbs  = require('express-handlebars');
    const path =require('path');

    const PORT = process.env.PORT || 5000;

    app.engine('handlebars', exphbs());
    app.set('view engine', 'handlebars');

    app.get('/', function (req, res) {
    res.render('home');
    }); 

terminal error

Failed to lookup view "home" in views directory "C:\Users\saved\desktop\stock\views"

When I hover over the home.handlebars file the path within my explorer is true "C:\Users\saved\desktop\stock\views\home.handlebars"

If I can see it's true when I hover, why is this error occurring? What am I not seeing?

I've been searching this for almost two days. This exercise was supposed to be my stress reliever. lol

1

There are 1 answers

0
Daniel Lockard On BEST ANSWER

Just to make this an official "Answer"... You need to put your "views" folder at the root, not inside public :)