Set up a Template Engine Keeps Failing

Tell us what’s happening:
I’ve done what the instructions asked and used the res.render() method to render the index.pug file but when I run the tests the 3rd test (Use the correct ExpressJS method to render the index page from the response) still fails. Please I need help, I’ve tried all I know.

Your code so far
Here’s a link to my code:
https://glitch.com/edit/#!/ballistic-energetic-aster

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36.

Challenge: Advanced Node and Express - Set up a Template Engine

Link to the challenge:

I am having the exact same problem. I went to your glitch link and see that you have continued as I see references to passport etc. Just wanted to check if you were able to resolve this problem?

Which glitch template did you start with? This was recently updated to avoid using Node process methods when structuring the file path. (process.cwd())
The instructions should provide some guidance here.

The path can be a relative path (relative to views), or an absolute path, and does not require a file extension.

*While Node process methods are available and technically work, we tried to guide campers to use basic path structuring without the additional helper methods.

Hi Jeremy,

Thanks for your speedy reply! I will quickly walk you through my process… I did try absolute path, also didn’t work.

  1. Go to boilerplate link from instructions
    https://glitch.com/edit/#!/remix/clone-from-repo?REPO_URL=https://github.com/freeCodeCamp/boilerplate-advancednode/
  2. Add pug (2.0.4) as suggested by search
  3. set view engine
  4. Change boilerplate code from
app.route("/").get((req, res) => {
  //Change the response to render the Pug template
  res.send(`Pug template is not defined.`);
});

to

app.route("/").get((req, res) => {
  //Change the response to render the Pug template
  res.render('/app/views/pug/index.pug');
});

Now all looks well in glitch but I still fail the third test.
Here is a link to the project, will leave it as is if you want to check it out?

https://yielding-wild-receipt.glitch.me

Thanks again for your help!

Note i checked the regex test from the commit which is:

assert.match(data, /res(\s+)?\.(r\w{5})\(('|")((\.{2})?)\/?(\w{3})\/(\w{5})('|")\)(;)?/gi, 'You successfully rendered the Pug template!');

which seems like this is the expected input then:

UPDATE:
This also satisfies the regex

res.render('pug/index');

(this was my first try, BUT I had to change

app.use("/public", express.static(process.cwd() + "/public"));

TO


app.use("/public", express.static(process.cwd() + "/views"));

Is this intentional or is an update on the boilerplate needed?

The way the Express static method is outlined in this boilerplate is only for the CSS assets. If you change the static path to views, it will never display the css, which I supposed is meaningless for most of this curriculum because it’s focused on a node app (backend).
But I digress, the expectation is as you indicated in your update but the changes to the static resource are unnecessary.
the regex is expecting (.{2})? there “might be” 2 leading periods but it’s tricky because you’re right, it only works with using /views/… or not at all. But the directions imply “relative to views”. Maybe we can take a look at modifying the test a bit.
Hope it helps!

1 Like

hi! sorry for my bad english. here is de answer. the test past ok

app.route("/").get((req, res) => {
//Change the response to render the Pug template
res.render(‘pug/index’);
});

2 Likes

hi @FernandoPi. thanks for your contribution but please refrain from posting the answers directly. You can use the [spoiler] tag in the forum to hide it from view, this will give other campers the benefit of not seeing the answer but reading your comments. You can type it directly or use the “gear” icon to find the blur option.