Beginner Node.js Interview QuestionsBeginnerComparison
Node.js · Question 11
What is the difference between Node.js and browser JavaScript?
Direct answer
Same language (ECMAScript), different runtimes — browsers add DOM, window, and layout; Node adds fs, process, http, and libuv-backed I/O with no document or rendering APIs.
JavaScript syntax you learn for React applies on the server, but globals and APIs differ. Code using document or localStorage fails in Node; code using fs or process fails in the browser unless bundled with polyfills.
| Browser | Node.js | |
|---|---|---|
| Global object | window | globalThis (global in CommonJS) |
| UI / DOM | document, alert, canvas | Not available |
| I/O | fetch, IndexedDB (sandboxed) | fs, net, child_process, pg client |
| Module systems | ES modules + bundlers | CommonJS + native ESM |
| Event loop | Rendering + tasks | libuv phases, no paint |
- Shared core — Promises, async/await, classes, Map/Set, optional chaining work in both.
- Isomorphic code — Zod schemas in packages/shared validate on web and API without DOM imports.
- Security model — browser sandboxes tabs; Node server has full filesystem and env access — validate inputs.
runtime-check.js
// Works in both
const total = [1, 2, 3].reduce((a, b) => a + b, 0);
// Browser only
if (typeof document !== "undefined") {
document.title = "AceDevHub";
}
// Node only
if (typeof process !== "undefined" && process.versions?.node) {
console.log("Node", process.version);
}