0Pricing
JavaScript Academy · Lesson

Globals, fetch availability, file/network APIs

Detect runtime safely (globalThis/window/global), check fetch availability, and understand why files need Node while browser focuses on DOM/network.

Globals, fetch availability, file/network APIs is a free JavaScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Big picture

Goal: Know where your code runs.

  • Globals: globalThis, window, global
  • fetch: feature-detect, not assume
  • Files: Node has fs; browsers do not
  • URLs: URL works in both
Globals, fetch availability, file/network APIs — illustration 1

Runtime sniff (safe)

Use typeof checks to avoid ReferenceErrors and learn where you are running.

// Detect presence of common globals
const hasWindow = typeof window !== "undefined";
const hasGlobal = typeof global !== "undefined";
const hasProcess = typeof process !== "undefined" && process && typeof process.version === "string";

console.log("globalThis exists?", typeof globalThis !== "undefined");
console.log("window?", hasWindow);
console.log("global?", hasGlobal);
console.log("Node process?", hasProcess);
Globals, fetch availability, file/network APIs — illustration 2

fetch: feature detection

Browsers usually have fetch; older Node versions may not. Check typeof fetch first.

// Feature-detect fetch; do not assume it exists everywhere
const hasFetch = typeof fetch === "function";
console.log("fetch available?", hasFetch);

// If available, you could call fetch(...). For a safe demo we only log.
if (!hasFetch) {
  console.log("Provide a fallback or use a library in Node versions without fetch.");
}
Globals, fetch availability, file/network APIs — illustration 3

Files: Node vs browser

Node exposes fs for files; the browser does not. Keep the same code path safe with a feature check.

// Files are a Node concern; browsers cannot read your disk directly
const hasRequire = typeof require === "function";
console.log("CommonJS require available?", hasRequire);

// Safe message instead of real file I/O (keeps the demo runnable everywhere)
if (hasRequire) {
  console.log("In Node you can use fs for files; in browsers you cannot.");
} else {
  console.log("No require here; likely a browser-like or sandboxed runtime.");
}
Globals, fetch availability, file/network APIs — illustration 4

Shared: URL API

The URL class parses addresses consistently across runtimes; handy for small tools.

// URL is available in both environments
const u = new URL("https://example.com/path?x=1#top");
console.log("host:", u.host);
console.log("pathname:", u.pathname);
console.log("search:", u.search);
console.log("hash:", u.hash);
Globals, fetch availability, file/network APIs — illustration 5

Beginner-friendly habits

Tips:

  • Check typeof fetch before using it.
  • Files need Node (e.g., fs); browsers focus on DOM and network.
  • Use globalThis for portable globals.
  • Prefer small feature checks over guessing the environment.
Globals, fetch availability, file/network APIs — illustration 6

fetch detection quiz

Quick check: Detect fetch safely.

Globals, fetch availability, file/network APIs — illustration 7

Recap

Recap: Detect runtime with safe typeof checks, feature-detect fetch, remember files are Node-side, and use URL in both worlds.

Globals, fetch availability, file/network APIs — illustration 8

Frequently asked questions

Is the “Globals, fetch availability, file/network APIs” lesson free?

Yes — the full text of “Globals, fetch availability, file/network APIs” is free to read here on the web, and the JavaScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the JavaScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Globals, fetch availability, file/network APIs”?

Detect runtime safely (globalThis/window/global), check fetch availability, and understand why files need Node while browser focuses on DOM/network. You practise JavaScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start JavaScript Academy?

No prior experience is required. JavaScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Globals, fetch availability, file/network APIs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this JavaScript Academy lesson?

Yes. Every JavaScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Globals, fetch availability, file/network APIs
  2. ESM loader quirks, path/URL differences
  3. Env variables & config patterns
← Back to JavaScript Academy