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

Carrie Happoldt
Carrie Happoldt
15,160 Points

Why don't I have to require pug?

I had assumed that we needed to require pug to get it to work (const pug = require("pug") ). Just like we had to require express.. But we don't have to and it still works. Why? How? Thanks!

1 Answer

andren
andren
28,558 Points

It works because this line:

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

Tells Express that you want it to use Pug to render the template. Express loads the view engine you set it to on its own. So you don't have to worry about it. It does this with any view engine that it is compatible with.

You can read about it on Express's template engine guide

Carrie Happoldt
Carrie Happoldt
15,160 Points

thanks for the link and answer! :D