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. This is lesson 1 of 3. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the JavaScript Academy learning path, and your progress syncs across the web and the CoddyKit app. The JavaScript Academy course includes 3 lessons in total.
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

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);

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.");
}

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.");
}

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);

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.

fetch detection quiz
Quick check: Detect fetch safely.

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

Learn JavaScript with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 59
- Lessons
- 200
Frequently Asked Questions
Is the “Globals, fetch availability, file/network APIs” lesson free?
Yes — any 3 lessons of the JavaScript Academy learning path, including “Globals, fetch availability, file/network APIs”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The JavaScript Academy course includes 3 lessons in total.
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, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 3.
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
- Globals, fetch availability, file/network APIs
- ESM loader quirks, path/URL differences
- Env variables & config patterns