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```
Please remove the backticks at the end of your file,
Please include this line in your file: const express = require("express");
You can use EJS instead of pug. It is more popular and easier to write and understand.
Assuming you have views folder at the root, you can delete this line:
// Set the views directory
app.set("views", path.join(__dirname, "views"));
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.