Functions in Javascript are not automatically a member of any particular object. If you want them to be, then you have to assign them that way.
It does so happen that in a browser, a function defined in the global scope will be attached to the window
object, but that is a nuance of the browser implementation, not of Javascript itself.
And, in fact the language is moving away form this since newer things like class
definitions in the top level scope are not attached to the window
object.
In node.js, your default top level scope is the module scope and functions defined there are not automatically attached to any object. If you want a function to be global, then you have to assign it to the global
object.
Though, please keep in mind that node.js has a modular architecture precisely so that you do NOT make functions you define global. Instead, you export them from a module and have any other module that wants to use them import
or require()
your module to get access to the function. In this way, all dependencies are explicitly declared in the code rather than implicitly defined in the code through globals.
So, in node.js if you want a function to be attached to an object, you have to explicitly put it on the object as a named property. Javascript does not provide a means in the language to iterate all objects/functions defined within a scope.