Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Express Basics (2015) Developing Express Apps Like a Boss Adding Routes to the App

Chris Reich
Chris Reich
15,163 Points

Why use express when building a blog and homepage?

So this is kind of a bigger picture question. I get that:

app.get('/', function (req, res) {
  res.send("<h1>I love Treehouse!</h1>");
});

. . . sends I love Treehouse to the homepage, but why would a developer choose to use express to do so instead of just coding the blog directly? What is the advantage or difference between coding sites directly and using platforms like node, express, etc.

Thanks.

1 Answer

Casey Ydenberg
Casey Ydenberg
15,622 Points

If by "directly" you mean building with HTML, CSS, and JavaScript, there are various advantages:

  1. Reusing code. HTML and CSS are declarative languages, they don't allow you to store data in variables or do loops or anything. To reuse anything, even the header and footer of a webpage, you would have to copy and paste large amounts of HTML. This is all fine until your site has lots of pages and you want to change anything.
  2. Dynamic output. A blog might have a comments section that processes input and displays the output, and allows the blog users to moderate them. Most blogging platforms have some kind of CMS to allow people who don't know any code to edit posts in an admin panel. The blog posts themselves are represented in many different places - in the post pages, on a blog listings page, on the homepage, in the sidebar ... all of those things can only be kept in sync by a computer program that keeps track of the most recent posts and outputs the right formats.
  3. Contact forms, sending emails, generating RSS feeds, calculating sales tax, anything resembling "programming" HTML can't do. It's a just a way of formatting text that can be understood by browsers.