Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

2.1K
Views
Failed to lookup view "index.ejs" in views directory

I have the following code in my express app (app.js file):

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

app.set('view engine', 'ejs');

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

app.listen(8080);

And the following dependencies:

"ejs": "^2.6.1",
"express": "^4.16.3",
"request": "^2.87.0"

And this is my folder structure:

myapp
   app.js
   package.json
   views
      index.ejs
   node_modules
      [all node files]

But when I run the app, it shows this error:

Failed to lookup view "index.ejs" in views directory "mylocaldirectory/myapp/views"

If it would help here are the other error messages:

  at Function.render (/mylocaldirectory/myapp/node_modules/express/lib/application.js:580:17)
    at ServerResponse.render (/mylocaldirectory/myapp/node_modules/express/lib/response.js:1008:7)
    at //mylocaldirectory/myapp/app.js:11:9
    at Layer.handle [as handle_request] (/mylocaldirectory/myapp/node_modules/express/lib/router/layer.js:95:5)
    at next (/mylocaldirectory/myapp/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/mylocaldirectory/myapp/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/mylocaldirectory/myapp/node_modules/express/lib/router/layer.js:95:5)
    at /mylocaldirectory/myapp/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/mylocaldirectory/myapp/node_modules/express/lib/router/index.js:335:12)
    at next (/mylocaldirectory/myapp/node_modules/express/lib/router/index.js:275:10)

I get no error if I just use res.send("SOME TEXT") but when I try to render an ejs file, it doesn't. What's the issue?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

You need to set your view directory and your viewengine before requesting any of your view files.

Hence you need to add the below lines, before your app.get

app.set('views', './views');
app.set('view engine', 'ejs');

And your res.render('index.ejs'); should be changed as,

res.render('index');

Hope this helps!

over 4 years ago · Santiago Trujillo Report

0

Did you set up the views folder?

app.set('views', './views')
over 4 years ago · Santiago Trujillo Report

0

First you have to tell express what view engine to use by setting

javascript // set the view engine to ejs app.set('view engine', 'ejs');

And when referring to a view you should leave out the extension. So instead of res.render('index.ejs'); use res.render('index');.

Setting up the view folder is not required since you're using the default view folder views to store your view files.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!