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

174
Visualizações
I'm trying to make a page navigation bar using express framework and pug library when I hit my endpoint demo page I got nothing on my screen. please h
enter code here

//Here is my app.js code, I want to make a basic routing navigation bar, here demo is my file name. I want to insert some HTML into the demo page but got nothing on the browser screen

const path = require("path");
const app = express();
const port = 80;

// For serving static files
app.use("/static", express.static("static"));

// Set the template engine as pug
app.set("view engine", "pug");

// Set the views directory
app.set("views", path.join(__dirname, "views"));

// Our pug demo endpoint
app.get("/demo", (req, res) => {
  res
    .status(200)
    .render("demo", {
      title: "Hey Harry",
      message: "Hello there and thanks for telling me how to use pubG!",
    });
});

app.get("/", (req, res) => {
  res.status(200).send("This is homepage of my first express app with Harry");
});

app.get("/about", (req, res) => {
  res.send("This is about page of my first express app with Harry");
});

app.post("/about", (req, res) => {
  res.send(
    "This is a post request about page of my first express app with Harry"
  );
});
app.get("/this", (req, res) => {
  res.status(404).send("This page is not found on my website cwh");
});

app.listen(port, () => {
  console.log(`The application started successfully on port ${port}`);
});```

    

    
    enter code here
//& Here is my code for demo.pug

  ```html 
      head 
        title=title 
      body 
        h1 = message```
      
 


 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Please remove the backticks at the end of your file,

  2. Please include this line in your file: const express = require("express");

  3. You can use EJS instead of pug. It is more popular and easier to write and understand.

  4. Assuming you have views folder at the root, you can delete this line:

// Set the views directory
app.set("views", path.join(__dirname, "views"));
  1. Adding one more res will make your code look more stylish and also less buggy (For instance, message line shouldn't have comma at the end):
app.get("/demo", (req, res) => {
  res.status(200);
  res.render("demo", {
      title: "Hey Harry",
      message: "Hello there and thanks for telling me how to use pubG!"
  });
});

I checked the your code on my computer and it worked. Please try the steps above and let me know if it works.

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