Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

200
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda