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 (2015) Getting Started with Express Install Express.js

Tom Nunn
Tom Nunn
16,333 Points

Should we get into the habit of using ES6 variable syntax with Express.js? (i.e const and let instead of var).

I've noticed Huston is using the var keyword to declare the variable instead of const in this case. Also, var is used a lot in the Express API documentation. Should we continue using var if this is the case?

Tom Nunn
Tom Nunn
16,333 Points

For example, can Express be required using the const keyword?

const express = require('express');

1 Answer

andren
andren
28,558 Points

The express.js tutorial was recorded before Treehouse decided to use ES6 in their JavaScript tutorials, that's the reason you don't see any example of const or let in them.

In addition to that ES6 has had somewhat incomplete support in node until the last year or so. That is likely why the Express.js docs are written in ES5.

However the current (and LTS) release of node now support 99% of ES6 features so it is completely safe to use. I personally always use const and let when coding in Node and Express and have had no issues whatsoever.

The biggest disadvantage of ES6 is that you have no guarantee that the person browsing your website has a browser new enough to work with it (which is where tools like babel come in) but that is not an issue with Node and Express. You don't have to worry about what your users use since all of the code is run on the server. So as long as node supports it you don't need to be afraid to use any ES6 feature you want.