Modules, Runtime & Tooling

Browser vs Node Environments

Browsers and Node both run JavaScript, but they expose different host APIs, globals, security models, module-loading behavior, and deployment constraints.
  • The same language runs in different hosts
  • Browser code runs in a user-agent sandbox
  • Node code runs with server/process capabilities
  • SSR and edge runtimes blur the boundary
  • Tooling may inject or replace values
Environment differences
ConcernBrowserNode
Global objectwindow / globalThisglobal / globalThis
UI APIsDOM, events, layoutNone by default
FilesystemRestricted / user mediatedfs module
Networkingfetch with CORS rulesfetch/http without browser CORS model
ConfigBundled public envprocess.env at runtime
Security boundaryUser sandboxServer/process permissions
Environment guard
export function isBrowser() {
  return typeof window !== "undefined" && typeof document !== "undefined"
}

if (isBrowser()) {
  // Safe to use DOM APIs here.
}
Guard environment-specific code; do not assume every runtime has every global.
Sources
  • Node.js Documentation and Learn Node.jsDifferences between Node.js and the Browser
  • MDN JavaScript Guide and ReferenceWeb APIs
  • Vite DocumentationEnvironment and client code