in my server.js:
If I type:
var yo = 123;
console.log(global.yo); // undefined
console.log(this.yo); // undefined
in the browser th
Short answer: no.
Slightly longer answer:
The Node.js documentation says:
In browsers, the top-level scope is the global scope. That means that in browsers if you're in the global scope
var somethingwill define a global variable. In Node this is different. The top-level scope is not the global scope;var somethinginside a Node module will be local to that module.
An important point to remember is that in Node.js, everything is a module. This includes entry files (i.e. files you run as node blah.js). So every variable being local to its module, they're not accessible on global like they would be on window in the browser:
var yo = 123;
console.log(window.yo); //⇒ 123
But in Node:
var yo = 123;
console.log(global.yo); //⇒ undefined
console.log(module.yo); //⇒ undefined
I can't find any documentation that points this behaviour out, though.