create-new-middleware challenges, about pug set code,can more simple
See original GitHub issueAffected 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:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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.
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