Browser vs Node Runtime
Differences between browser and Node runtimes, and how their environments affect APIs and behavior.
Short explanation
Browsers provide DOM, BOM, and event-driven user APIs, while Node.js exposes system APIs (filesystem, network) using the same underlying JavaScript engine (V8 in Node) but different standard libraries.
Real-world example
// Browser
document.getElementById('app').textContent = 'Hello';
// Node
import fs from 'fs';
const data = fs.readFileSync('./file.txt', 'utf8');
console.log(data);
How JS handles it internally
The engine executes JavaScript similarly, but the runtime injects or provides different global objects and APIs. Node also has its own event loop integration with libuv for asynchronous I/O.
Related
π Related:
FAQ
Q: Can I run browser code in Node?
A: Not directly β the DOM and browser-specific APIs don't exist in Node, but tools like JSDOM can emulate parts of the DOM for testing.