Skip to main content

Node.js vs the browser

1. Where the code runs

EnvironmentWhere it runsMain purpose
Node.jsOn a server or locally on a machineServer logic, APIs, automation, utilities
BrowserOn the client side (in the user's browser)UI work, DOM, user interaction

2. Available APIs and environment

CapabilityNode.jsBrowser
Filesystem accessYes, fsNone
Network access (TCP, HTTP server)Yes, http, netPartial: only HTTP requests via fetch
DOM access (HTML, page elements)NoneYes
Web APIs (fetch, localStorage, WebSocket)Partial (Node 18+ added some)Full access
Global objectsglobal, process, __dirnamewindow, document, navigator

3. Modules and dependencies

FeatureNode.jsBrowser
Module systemCommonJS (require) and ES Modules (import)ES Modules only
Package managernpm, pnpm, yarnNone (needs a bundler - Webpack, Vite, etc.)
Importing packagesDirectly from node_modulesVia 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

AspectNode.jsBrowser
System accessYesNone
Code isolationNone (code can access the disk and network)Yes (sandbox)
Trust levelServer-side codeUntrusted 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

CriterionNode.jsBrowser
Runtime environmentServerClient
DOM / UINoneYes
Filesystem accessYesNone
SecurityLess restrictedSandboxed
Main jobServer logic, APIsRendering the UI, UX

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.