Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

204
Vistas
What can I do to render this EJS template file?

My app does not work. I've reduced the code to bare basics trying to find the mistake. Any ideas?

This is the project file structure. There are no other files or folders besides the listed below.

  • Project folder (folder)
    • app.js (file)
    • views (folder)
      • home.ejs (file)

This is the app.js content:

// jshint esversion:6
const express = require(`express`);
const ejs = require(`ejs`);
const app = express();

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

app.get("/", function(req, res) {
  res.render(`home`);
});

app.listen(3000, function() {
  console.log(`The server is now on.`);
});

This is the home.ejs content:

<!DOCTYPE html>
<html lang=`en` dir=`ltr`>

<head>
  <meta charset=`utf-8` />
  <title>Secrets</title>
</head>

<body>
  <h1>Secrets</h1>
</body>

</html>

I ran npm init to create this app and npm i express ejs to install the dependencies.

The error I get is the following:

Error: Failed to lookup view "home" in views directory...full path

Any ideas why this is not running properly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are missing to state where the root folder for ejs files will be.

var path = require('path');
app.set('views', path.join(__dirname, './views'));

Also, for me I set view engine like this:

app.engine('.ejs', ejs.__express);

For me it works, see a glitch for a demo.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda