Views directory

 Whenever we are running the server from another directory other than the directory in which the index.js exists an error occurs inorder to solve this we use views directory

use this code whenever we use views to run it from different directories

const path = require("path");
app.set("views", path.join(__dirname, "/views"));


use it is as default

const express = require("express");
const app = express();
const path = require("path");

const port = 8080;
app.set("view engine", "ejs");

app.set("views", path.join(__dirname, "/views"));

app.get("/", (req, res) => {
  res.render("home.ejs");
});
app.listen(port, () => {
  console.log(`server is listening on port ${port}`);
});

if we run the server from NODE JS directory ,in the teriminal the command should be : nodemon EJS/index.js




Comments

Popular posts from this blog

DATABASE RELATIONSHIPS

ROUTING (GET /) home route

Query Strings