Globals (Node.js)

Node.js globals are objects available everywhere without importing, such as process, console, Buffer, __dirname, setTimeout, and globalThis. They differ from browser globals like window and document.

Node.js

Some identifiers are available in every module without a require/import. The big ones are process (the running process), console (logging), Buffer (binary data), the timer functions (setTimeout, setInterval, setImmediate), and globalThis (the global object, equivalent to window in browsers).

Module-scoped 'globals' like __dirname, __filename, require, module, and exports are technically provided per-module rather than truly global, but they are always there in CommonJS files. URL, TextEncoder/TextDecoder, and fetch (in recent Node versions) are also globally available.

Coming from the browser, note the differences: there is no window, document, or localStorage in Node, and the global object is global or globalThis instead of window. Avoid creating your own global variables; prefer module exports so dependencies stay explicit.

Syntax

process, console, Buffer, __dirname, setTimeout, globalThis

Examples

JavaScript

// all available without importing
console.log(globalThis === global);     // true
console.log(typeof process);            // object
setTimeout(() => console.log("later"), 0);

Output:

true
object
later

Learn it in a lesson

See also

Back to the Dictionary