In Node.js, any code that we write in a module will be wrapped in a function. You can learn more about this in this detailed answer . Thus, this at the top level of the module will refer to the context of this function, and not to the global object.
In fact, you can use the global object to refer to the actual global object, e.g.
function a() { console.log('is this the global object? ' + (global === this)); } a();
source share