Suggest an editImprove this articleRefine the answer for “Node.js vs the browser”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**Node.js and the browser** both run the V8 engine, but expose different APIs: Node.js can access the filesystem and network and has no DOM, while the browser has the DOM and Web APIs but runs sandboxed. **Key point:** Node.js is a server environment with no DOM, the browser is a client environment with no filesystem access.Shown above the full answer for quick recall.Answer (EN)Image## 1. Where the code runs | Environment | Where it runs | Main purpose | |---|---|---| | **Node.js** | On a server or locally on a machine | Server logic, APIs, automation, utilities | | **Browser** | On the client side (in the user's browser) | UI work, DOM, user interaction | ## 2. Available APIs and environment | Capability | Node.js | Browser | |---|---|---| | Filesystem access | Yes, `fs` | None | | Network access (TCP, HTTP server) | Yes, `http`, `net` | Partial: only HTTP requests via `fetch` | | DOM access (HTML, page elements) | None | Yes | | Web APIs (`fetch`, `localStorage`, `WebSocket`) | Partial (Node 18+ added some) | Full access | | Global objects | `global`, `process`, `__dirname` | `window`, `document`, `navigator` | ## 3. Modules and dependencies | Feature | Node.js | Browser | |---|---|---| | Module system | CommonJS (`require`) and ES Modules (`import`) | ES Modules only | | Package manager | npm, pnpm, yarn | None (needs a bundler - Webpack, Vite, etc.) | | Importing packages | Directly from `node_modules` | Via bundling into a single file | ## 4. Architecture and asynchrony - **Both environments run the V8 engine**, but Node.js wraps it with its own system APIs. - Node.js uses the **event loop** for asynchronous I/O: reading files, requests, processes. - In the browser, the event loop handles UI events: clicks, timers, requests to the server. ## 5. Security and access | Aspect | Node.js | Browser | |---|---|---| | System access | Yes | None | | Code isolation | None (code can access the disk and network) | Yes (sandbox) | | Trust level | Server-side code | Untrusted environment (the user's browser) | ## 6. Examples of code differences **Node.js:** ```javascript // Working with files const fs = require('fs'); fs.writeFileSync('text.txt', 'Hello from Node.js!'); ``` **Browser:** ```javascript // Working with the DOM document.body.innerHTML = '<h1>Hello from Browser!</h1>'; ``` ## Quick summary | Criterion | Node.js | Browser | |---|---|---| | Runtime environment | Server | Client | | DOM / UI | None | Yes | | Filesystem access | Yes | None | | Security | Less restricted | Sandboxed | | Main job | Server logic, APIs | Rendering the UI, UX |For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.