question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

create-new-middleware challenges, about pug set code,can more simple

See original GitHub issue

Affected page

https://www.freecodecamp.org/learn/quality-assurance/advanced-node-and-express/create-new-middleware

Your code

app.set('view engine', 'pug');
app.set('views', './views/pug')

it set pug as view engine, and set Express look for your templates in ‘./views/pug’

so the code

app
 .route('/profile')
 .get(ensureAuthenticated, (req,res) => {
    res.render(process.cwd() + '/views/pug/profile');
 });

can write into

app
 .route('/profile')
 .get(ensureAuthenticated, (req,res) => {
    res.render('profile');
 });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
raisedadeadcommented, Dec 18, 2021

While in practice the code that the OP shared is better, this challenge’s scope (and for that matter any challenge on freeCodeCamp) is not to teach best practice while teaching a concept.

The idea is to limit the scope of the lesson to get the concept across without too many abstractions.

IMHO, the code in the current lesson eliminates the need for teaching setting options which are covered elsewhere. I don’t think we need to update the challenge.

0reactions
miyaliu666commented, Dec 18, 2021

I just met with @luojiyin1987 during the Chinese contributors meeting. He meant the code in the challenge could be improved. Could you check the challenge and confirm if it’s necessary? Thanks! @raisedadead

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-Side Rendering with Pug Templates | by Daniel Wagener
We need to create some sort of middleware that will determine whether a user is logged in or not. That way, we'll know...
Read more >
Node.js and Express Tutorial: Build a Website Using Pug - Auth0
Learn how to use Express and the Pug template engine to build a website in Node.js. Create user interfaces using Pug and CSS...
Read more >
Express Explained with Examples - Installation, Routing ...
This command will install the pug and to verify that installed correctly, just take a look at the package. json file. To use...
Read more >
Node.js "Pug" Server-Side Template Injection - YouTube
https://j-h.io/snyk Huge thank you to Snyk for sponsoring this video! Try Snyk for FREE to find vulnerabilities in your own applications ...
Read more >
Go Fiber by Examples: How can the Fiber Web Framework be ...
Built-in middleware for most tasks; Rich and robust routing; Easy serve static files and work with databases; Support of all popular template ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found