title: Error: ENOENT: no such file or directory in express-handlebars
body: <p>I am using <code>express-handlebars</code> to load dynamic content in NodeJS</p>
  
  <p>inside <code>app.js</code></p>
  
  <pre><code>const express = require("express");
  const bodyParser = require("body-parser");
  const path = require("path");
  const pp = require("./util/path.js");
  const adminRoutes = require("./routes/admin");
  const shopRoutes = require("./routes/shop");
  const expressHbs = require("express-handlebars");
  const app = express();
  
  app.engine("hbs",expressHbs());
  app.set("view engine", "hbs");
  app.set("views", "views");
  
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(express.static(path.join(__dirname, "public")));
  
  app.use("/admin", adminRoutes.routes);
  app.use(shopRoutes);
  
  app.use((req, res, next) =&gt; {
    res.status(404).render("404", { pageTitle: "Page Not Found" });
  });
  app.listen(3001, "localhost", () =&gt; console.log("Listening on 3001 PORT"));
  
  </code></pre>
  
  <p>When <code>expressHbs()</code> function has no param it shows the following error</p>
  
  <blockquote>
    <p>Error: ENOENT: no such file or directory, open 'C:\dev\nodejs\maximi_course\views\layouts\main.handlebars'</p>
  </blockquote>
  
  <p>And when i pass an option object to it:</p>
  
  <pre><code>app.engine(
    "hbs",
    expressHbs({
      extname: "hbs",
      layoutsDir: path.join(__dirname, "views")
    })
  );
  </code></pre>
  
  <p>It shows:</p>
  
  <blockquote>
    <p>Error: ENOENT: no such file or directory, open 'C:\dev\nodejs\maximi_course\views\main.hbs'</p>
  </blockquote>
  
  <p>I've searched for a solution but i got no result , Actually i am following a tutorial and i have done the same as teacher did but i got an error.</p>
  
  <p>Lastly thing that i have tried is adding <strong>defaultLayout</strong> property and it works and load the default but when i change the url to another page it always load the same page which i set as default</p>
  
  <p>Here is project folder and all its contents</p>
  
  <p><a href="https://i.stack.imgur.com/IFyW1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/IFyW1.png" alt="Directory"></a></p>