Beginner Node.js Interview QuestionsBeginnerConcept
Node.js · Question 20
What is the global object in Node.js?
Direct answer
globalThis (alias global in Node) is the top-level object — unlike browser window, Node exposes process, Buffer, and timers on global; prefer explicit imports (node:fs) over relying on globals in application code.
ECMAScript standardized globalThis so the same code can access the global object in browser and Node. Node still adds runtime-specific properties not found in browsers.
| Global | Node | Browser |
|---|---|---|
| globalThis | Yes | Yes (window in browsers) |
| process | Yes — env, argv, exit | No |
| Buffer | Yes — binary data | No (Uint8Array instead) |
| document | No | Yes |
| setTimeout / setInterval | Yes | Yes |
- No var pollution needed — top-level const/function in modules are module-scoped, not global.
- global.user = x anti-pattern — hides dependencies; use explicit modules or DI.
- ESM strict — modules run in strict mode; this at top level is undefined.
global-demo.mjs
console.log(globalThis === global); // true in Node
console.log(process.version);
console.log(Buffer.from("hi").toString()); // Buffer is global
// Module scope — not on global
export const API_PORT = 4000;