TIL that node programs have different globally accessible objects than those found in the browser.
Globals in the browser
In the browser, we have access to two global objects:
document is an object that points to the highest parent node of your currently visible document object model (DOM). Since it is a globally accessible object created by the browser, it is also a property on window.
document returns an array of 1 element: the outermost HTML tag of the currently visible DOM.
The equivalent objects in a
node program are named
Since there isn’t a browser
window in a
node program (code can execute anywhere, not just in the browser) the highest-level scope in your node program is called
global. It can be interacted with in the same way as the
window object, and like
window it also contains globally accessible objects and methods for your node program (e.g.
console). You may also reference these global properties without explicitly calling them from
Similarly, since code is not executing in the browser, there is no DOM available to a
node process. There are, however, APIs that
node exposes to interact with the running node process.
node exposes these APIs to the user in a second global object called
The objects and APIs available from
process give you access to details about the environment in which the node process is running.
process.env many times to grab environment variables from my execution environment, but I never took time to look at what else was exposed to a program via process (like