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 Your First Express App

why 'use strict'; and var express = require('express'); are surrounded by rectangular structure highlighting them?

"use strict";  

var express = require('express');

var app = express();  

app.listen(3000);   

screenshot

1 Answer

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

It's probably your javaScript linter flagging it as invalid javaScript. Just put this at the top of your page

/*jslint node: true */ 

to let the linter know that it's a node project. Should look like this:

/*jslint node: true */
"use strict";  

var express = require('express');

var app = express();  

app.listen(3000);   
Nathan Brenner
Nathan Brenner
35,844 Points

Is that because the client side javaScript interpreter doesn't recognize 'require' and 'use strict'?

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

Yes. Mostly. My understanding is that the linter is checking for standard javaScript and so you bascially want to tell the linter to check your code in node mode. Otherwise, for starters, require() isn't defined, so that should definitely throw an error.

As far as "use strict", I was taught that you always want to use "use strict" inside of functions (in standard javaScript) because in the global scope strict mode will apply not just to your script, but to any scripts loaded after it is first used (even if the scripts were not written in strict mode).

So if other scripts are loaded after yours that were not written in strict mode then it will trigger errors.

Here is a test that I screen captured to show that it doesn't trigger an error if used inside of a function. Also it shows that the node: true comment removes the lint errors.

http://screencast.com/t/3dahZ5braSQ