//test.js
console.log(this);
By executing the test.js with command 'node test.js', I got result of '{}'. But by executing the same code in REPL, I got tons of system information. Why this difference? Is it because of my configuration of Node?
//test.js
console.log(this);
By executing the test.js with command 'node test.js', I got result of '{}'. But by executing the same code in REPL, I got tons of system information. Why this difference? Is it because of my configuration of Node?
Different execution contexts.
In node, any file you require is a module that has its own scope, by default an empty object (hence the {}), until you export something.
The repl, on the other hand, is its own execution context with a bunch of stuff already attached to it. You can even set things up to attach to it yourself (e.g. Convenient functions)