I am beyond confused, I have made all the changes that seem correct and I still get an error.
This is the changes I made to server.js file:
"use strict";
const express = require("express");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
const pug = require('pug');
const app = express();
fccTesting(app); //For FCC testing purposes
app.use("/public", express.static(process.cwd() + "/public"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'Pug');
app.route("/").get((req, res) => {
//Change the response to render the Pug template
res.render(__dirname+'/views/pug/index.pug');
//res.send(`Pug template is not defined.`);
});
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port " + process.env.PORT);
});
I have tried different variations, and I can’t find any help on whats wrong. Please help!
ILM
January 6, 2025, 11:36am
2
can you provide a link to the challenge?
ILM
January 6, 2025, 11:37am
3
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>
) to add backticks around text.
See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').
1 Like
Thank you for correcting the format <3
It’s been a while since I played with Node, but I think I can help.
It looks like you overlooked Step 3 to set the views property. And pug may need to be lowercase when setting the view engine property…like the example given in the instructions.
Hope that helps.
1 Like
thank you a million for your reply, i’ve made some changes according to what you said, does this seem right??
"use strict";
const express = require("express");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
const pug = require('pug');
const app = express();
fccTesting(app); //For FCC testing purposes
app.use("/public", express.static(process.cwd() + "/public"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.set('view engine', 'pug');
app.set('views', './views/pug');
app.route("/").get((req, res) => {
//Change the response to render the Pug template
res.render(__dirname+'./views/pug/index.pug');
res.render('index');
//res.send(`Pug template is not defined.`);
});
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port " + process.env.PORT);
});
I don’t think you want this
res.render(__dirname+'./views/pug/index.pug');
Only the res.render
that renders the index
1 Like
thank you for your advice!
Thank you all for your help, I’ve managed to complete the lesson <3