Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Express Basics Using Templates with Express Using Pug in Your Express App

Michael Pashkov
Michael Pashkov
22,024 Points

If we had site with 1000 pages, should we make 1000 routes and templates?

If we had site whit 1000 pages, should we make 1000 routes and templates? like app.get('/', (req, res) => { res.render('index'); });

3 Answers

Kevin Korte
Kevin Korte
28,149 Points

Probably, not - this becomes unscalable, if not already.

Try viewing templates as how many different view types you might have, for example

  • Homepage
  • Login
  • Signup
  • Password reset
  • Profile page
  • Article

etc, for whatever type of site or app you're using.

For your routes, let's say you have 1000 users, you'd have 1000 profile pages, but you should be able to route all 1000 users profile pages through one route, and one template, using wildcards to do so, for instance app.get('/:user', (req, res) => { res.render('profilepage'); });

Michael Pashkov
Michael Pashkov
22,024 Points

Thank you Kevin. This issue was nagging me. Continue understanding Express and routes.

Dilip Agheda
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dilip Agheda
Full Stack JavaScript Techdegree Graduate 28,581 Points

I have only completed first 20% of express course but i can imagine regex at rescue for 1000 page scenario. I guess that any web framework + templating engines would have features like:

  • use regex to create a route pattern which matches at run time
  • use query string parameters to drive different response.
  • use database that stores data that will go into templates as content
  • insert one template into another template (e.g., header , footer)

etc.