█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/Programming Languages/JavaScript (Standalone Deep Dive)/Browser vs Node Runtimes
35 minIntermediate

Browser vs Node Runtimes

After this lesson, you will be able to: Distinguish browser JS from Node.js: the global object, APIs available in each, when code transfers between them.

Same language, different runtimes. Knowing what's available where prevents 'works in browser, broken in Node' bugs.

Prerequisites:Functional Programming

Same language, different APIs

Both runtimes implement the JS language (ECMAScript). They differ in built-in APIs. Browser: DOM, fetch, localStorage, IndexedDB, Web Crypto, postMessage, navigator. Node: fs, path, http, crypto (Node-specific), Buffer, process, child_process. Shared (in modern Node 20+): fetch, AbortController, URL, structuredClone, console.

The global object

Same name `globalThis` in both runtimes.

tsx
// Modern (works in both)
globalThis.foo = 1;
// Browser-specific
window.foo = 1; // same as globalThis.foo in browser
// Node-specific
global.foo = 1; // same as globalThis.foo in Node
// Detect runtime
if (typeof window !== "undefined") {
// browser
} else if (typeof process !== "undefined") {
// node
}

Modules: ESM vs CommonJS

ESM (modern): `import / export`. Works in browsers natively (with type="module") and in Node 14+ when package.json has `"type": "module"`. CommonJS (Node legacy): `require / module.exports`. Default for older Node packages. Modern projects: ESM everywhere. Some legacy Node libs still need CommonJS interop.

Edge runtimes (Vercel Edge / Cloudflare Workers)

A third class of runtime: V8 isolates without the full Node API. Available: fetch, URL, crypto, Request/Response. NOT available: fs, child_process, most Node-specific APIs. Same code can run in browser + edge with minimal changes. Node-only code (fs, etc.) breaks.

Common mistakes only experienced JS devs avoid

Using `window.location` in code that runs server-side. Crash on SSR. Using `process.env` in browser code. Bundled bundlers inline at build time but raw `process` is undefined. Mixing CommonJS and ESM in one project carelessly. Calling `fs.readFile` in an Edge function. Edge runtimes don't have fs.

Quick Check

Which API is NOT available in Cloudflare Workers / Vercel Edge?

Pick the Node-only one.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Functional Programming in JS
Back to JavaScript (Standalone Deep Dive)
Modules: ESM vs CommonJS→