The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Understand Global Namespace in Node.js

Understand Global Namespace in Node.js

4:42
In this lesson, we introduce the node global namespace object and demonstrate how global variables in node may not behave the way you think they do. We also briefly discuss the global 'require' object and how it operates in the global namespace.
Watch this lesson now
Avatar
egghead.io

In this lesson, we introduce the node global namespace object and demonstrate how global variables in node may not behave the way you think they do. We also briefly discuss the global 'require' object and how it operates in the global namespace.

Avatar
Stephen

Just to clarify, global variables in a module that we import via require are NOT global in the application. Is that correct?

In reply to egghead.io
Avatar
Will

Yes- absolutely correct.

In reply to Stephen
Avatar
Jeff

If you declare a global var called globalFoo in file module1.js, then...

var modFoo = require('./module1.js');

var newFoo = require('./module2.js');

Will the global var globalFoo be global to newFoo as well?

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?