Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
897 views
in Technique[技术] by (71.8m points)

node.js - when i include header.ejs and footer.ejs in home.ejs file there is an include file error

When I include header and footer files it is showing an error

[ ][1]Error: C:Usersgajulejschallengestartingfilesejschallengeejs-challengeviewshome.ejs:6
    4|     <meta charset="utf-8">
    5|
 >> 6|     <%- include('views/header'); %>
    7|   </head>
    8|   <body>
    9|     <h1>Home</h1>

Could not find the include file "views/header"

    const express = require("express");
    
    
    const app = express();
    
    app.set('view engine', 'ejs');
    app.set("views",__dirname+"/views");
    app.use(bodyParser.urlencoded({extended: true}));
    app.use(express.static("public"));
    
    
    app.get("/",function (request,response) {
    response.render("home",{homeStartingContent:homeStartingContent});
    });
    
    app.listen(3000, function() {
      console.log("Server started on port 3000");
    });

my app.js file

this is my HOME.EJS

    <<!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
    
        <%- include('views/header'); %>
      </head>
      <body>
        <h1>Home</h1>
        <p>
          <%= homeStartingContent%>
          </p>
    
      </body>
      <%- include('views/footer');%>
    </html>
question from:https://stackoverflow.com/questions/65951556/when-i-include-header-ejs-and-footer-ejs-in-home-ejs-file-there-is-an-include-fi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...