Could not find the include file "partials/header"
For some reason my NODE JS program couldn't find the .ejs file i am trying to include in my file.
My path of views looks like
views ├───page │ index.ejs │ └───partials footer.ejs header.ejs
Index.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>News Node App</title>
<%- include("partials/header"); %>
</head>
<body>
<div class="d-flex">
<%for (let i =0;i<articles.length;i++){ let currNews = articles[i]%>
<li>
<div class="news-cars">
<%=currNews.title%>
</div>
</li>
<%}%>
</ol>
</div>
</body>
</html>
header.ejs I am planning to add navbar later
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous"
/>
The full log to the error is given below
Error: D:\node\blog-app\views\page\index.ejs:7
5| <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6| <title>News Node App</title>
7| <%- include("partials/header"); %>
8| </head>
9| <body>
10| <div class="d-flex">
Could not find the include file "partials/header"<br>
at getIncludePath (D:\node\blog-app\node_modules\ejs\lib\ejs.js:183:13)<br>
at includeFile (D:\node\blog-app\node_modules\ejs\lib\ejs.js:309:19)<br>
at include (D:\node\blog-app\node_modules\ejs\lib\ejs.js:689:16)<br>
at eval (D:\node\blog-app\views\page\index.ejs:10:17)<br>
at index (D:\node\blog-app\node_modules\ejs\lib\ejs.js:691:17)<br>
at tryHandleCache (D:\node\blog-app\node_modules\ejs\lib\ejs.js:272:36)<br>
at View.exports.renderFile [as engine] (D:\node\blog-app\node_modules\ejs\lib\ejs.js:489:10)<br>
at View.render (D:\node\blog-app\node_modules\express\lib\view.js:135:8)<br>
at tryRender (D:\node\blog-app\node_modules\express\lib\application.js:640:10)<br>
at Function.render (D:\node\blog-app\node_modules\express\lib\application.js:592:3)<br>
at ServerResponse.render (D:\node\blog-app\node_modules\express\lib\response.js:1012:7)<br>
at D:\node\blog-app\controllers\news-controller.js:10:25<br>
at processTicksAndRejections (internal/process/task_queues.js:97:5)<br>
Try adding ./partials/header
.
You should also set the views engine in your main.js file app.set('view engine','ejs')
. After installing the ejs
package.