What is the difference between Node.js and the browser JavaScript environment?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Node.js development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

Both Node.js and the browser run JavaScript using the V8 engine, but they operate in fundamentally different environments. The browser provides APIs for DOM manipulation (document, window), browser storage (localStorage, cookies), Web APIs (fetch, WebSockets), and user interaction events. Node.js has no DOM — instead it provides APIs for the operating system: fs (file system), http (networking), path, os, child_process, and more. Node.js uses CommonJS modules (require()) and now supports ES Modules; browsers primarily use ES Modules (import/export). Node.js has access to the local file system; browsers do not (for security). Global objects also differ: browser has window, Node.js has global (now globalThis in both).

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Node.js codebase.