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
| Concern | Browser | Node |
|---|---|---|
| Global object | window / globalThis | global / globalThis |
| UI APIs | DOM, events, layout | None by default |
| Filesystem | Restricted / user mediated | fs module |
| Networking | fetch with CORS rules | fetch/http without browser CORS model |
| Config | Bundled public env | process.env at runtime |
| Security boundary | User sandbox | Server/process permissions |
export function isBrowser() {
return typeof window !== "undefined" && typeof document !== "undefined"
}
if (isBrowser()) {
// Safe to use DOM APIs here.
}