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
Jason Pallone
11,340 PointsUsing HTML and express?
So with express we can use PUG, but could I do my HTML and CSS on the frontend with javascript, and use express for the backend? Or do I need to use PUG in order to use express? Which is more commom/better if this is possible?
Thanks in advance!
1 Answer
Aayush Mitra
24,904 PointsHello! You can use normal HTML with express by serving in as a static file. But this is not as common to do because when you serve HTML files in express, you cannot give dynamic data to them. Whereas in PUG you can give dynamic data to the page because it is a templating engine. One way to actually give dynamic data by just using HTML is making an express api that serves JSON. Then in the front end JavaScript you can use the fetch api to make requests to that api and you can insert that data into the HTML so that it is dynamic. But that method is quite time consuming and it is really unnecessary. The only time you probably would want to use that method is with a JavaScript framework. I would suggest that you stick with PUG. If you have already written HTML code and wish to convert it to PUG, there is an online converter where you just paste in the HTML code and it converts it into PUG code.
I hope this makes sense!
Thanks :)
Jason Pallone
11,340 PointsJason Pallone
11,340 PointsOk thanks that does make sense!