Framework vs library: who calls whom
You call a library; a framework calls your code. That inversion of control is the real split.
Published here , updated · 5 sources · Resume reading
A library is code you call; a framework is a structure that calls your code. MDN names that inversion of control as the key difference between those two shapes [1]. Related reads stay useful: what is an API and what is HTTP.
Quick start (under a minute)
Pick any file where you import a helper and invoke it yourself. That is library usage: your main or route handler stays in charge [1] [2].
Now pick a file where you export GET or POST and never call those functions yourself. Something else (the framework router) dispatches them when a URL matches. That is framework usage: you filled slots in someone else's lifecycle [2].
If both happen in one repo, you likely have a framework plus libraries inside it.
Draw control flow before debating logos
web.dev compresses the idea into one sentence: application code calls library code; framework code calls application code [2]. Fowler's older inversion-of-control essay calls the same pattern "Hollywood: don't call us, we'll call you" for frameworks and containers [3].
The diagram is about who owns the spine of execution, not about file size. A one-function npm package can be a library. A multi-megabyte download can still be mostly libraries if your code keeps the main loop.
Run a tiny Node contrast on this host
Observed on this draft host (Node v22.23.5, 2026-12-03):
function capitalize(s) {
return s.charAt(0).toUpperCase() + s.slice(1);
}
console.log("library path:", capitalize("hello framework"));const routes = { "/": () => "framework called this handler" };
console.log("framework path:", routes["/"]());node -e 'function capitalize(s){return s.charAt(0).toUpperCase()+s.slice(1);} console.log("library path:", capitalize("hello framework"));'
node -e 'const routes={"/":()=>"framework called this handler"}; console.log("framework path:",routes["/"]());'library path: Hello framework
framework path: framework called this handlerFirst block: you invoked capitalize when you chose (same call direction MDN uses for lodash) [1]. Second block: a toy router called your handler; you registered it but did not dispatch it yourself. Real frameworks hide that table inside server bootstrap [2].
Use examples without brand wars
MDN lists jQuery, Mootools, and React as libraries, and Angular and Ember as frameworks [1]. Labels on marketing sites move with product strategy. The call-direction test survives rebrands.
Need one sharp tool (hash a string, parse an ISO date, draw a chart): reach for a library. Need opinionated routing, dependency injection, project layout, and a prescribed boot sequence: you are buying into a framework shape even if the install command says npm i some-lib.
Either way, remote services still speak HTTP (what is HTTP). Frameworks add routers, serializers, and middleware; libraries add functions you call from your own control flow.
Fowler's inversion is wider than npm
Fowler's IoC piece is about object graphs and containers, not only front-end SPAs [3]. Back-end frameworks (Rails, Spring, ASP.NET) call your controllers when a request arrives. Game engines call your update and render each frame (what is a game loop). The pattern repeats: framework sets the schedule; you supply callbacks.
Do not treat "framework" as insult or "library" as praise. Treat them as control-flow facts so you can estimate migration cost. Replacing a date library is a function swap. Replacing a framework is rewiring who owns boot, config, and lifecycle.
What inversion of control changes in tests
When you call a library, unit tests mock the library boundary you import. When a framework calls you, tests must boot enough framework to trigger your hook or use the framework's official test toolkit [3]. That is why framework migrations show up in QA calendars even when "no business logic changed."
Dependency injection containers (Spring, .NET hosts) are framework-adjacent: they decide which implementation your constructor receives [3]. You still write classes, but the container chooses when to construct them. That is IoC without necessarily being a game engine or a SPA router.
Backend request cycle as a framework example
An HTTP framework owns the socket loop (or worker pool), parses the request, matches a route, then calls your controller function [2]. You did not write the listening loop. You exported a function with a signature the framework documents. Middleware stacks are chained callbacks the framework invokes before and after your handler. Libraries such as a JWT verifier still appear inside that chain, but the chain itself is framework code.
Contrast: a script that uses urllib or fetch in a while loop you wrote is library style. You chose sleep, retry, and logging order. Nobody called your main except the shell.
Microservices still use both words
A small Go binary that imports net/http and calls ListenAndServe with a handler you register looks like framework usage at the HTTP boundary: the server calls your handler per request [2]. Inside the handler you may call dozens of libraries (metrics, SQL drivers, validators). Teams describe the service as "plain Go" because no giant vendor framework owns the repo, but the call direction at the socket edge is still inverted.
Platform teams sometimes ship an internal "SDK" that is really a thin framework: it owns process startup, config loading, and signal handling, then calls your Run method. Naming it SDK does not change the Hollywood rule [3].
When you interview or review a design doc, ask where main equivalent lives. If the answer is "the framework boots and discovers plugins," plan for framework upgrades and security patches on that spine before you add features.
Failure modes worth naming
Counting file size or star count. A framework can be small; a library ecosystem can be huge. Ask who calls whom.
Calling React a framework because "we built an app with it." React is often a UI library you call from your components; the framework character may come from Next, Remix, or your own router plus data layer [1].
Frameworks free you from architecture. Frameworks choose defaults, not your domain model. You still design APIs, errors, and data boundaries (what is an API).
Importing a framework for one function. Shipping Express only to use express.static is framework weight for library work. A smaller static server or a direct call to send may fit.
Ignoring lock-in on the main loop. Whoever owns the loop decides middleware order, error handling, and testing hooks. Know that before you embed business rules in framework-specific hooks.
Sketch who calls main on the whiteboard before you add a framework dependency for one helper. Label one real import as library style and one exported route as framework style in the same repo. Framework handlers still return JSON defined by what is an API, and every outbound call still rides what is HTTP no matter who dispatched the handler.
Send this to the friend who calls every dependency a framework.

Keep this guide
Filed under Dev explainers
Questions about this guide
What is the key difference?
MDN and web.dev both state it as control flow: with a library, your application code calls exported functions when you choose. With a framework, the framework owns the main lifecycle and calls your hooks, handlers, or methods when its rules say so. Marketing labels disagree; the call-direction test still holds.
Is React a library or a framework?
MDN classifies React as a library and names Angular and Ember as frameworks. React can sit inside a larger framework shape (Next.js, Remix). Ask who schedules renders and who owns routing, not what the landing page claims.
Can a framework include libraries?
Yes. Frameworks bundle utilities, HTTP clients, and date parsers. The architectural question stays the same: who drives the event loop or request cycle, and who registers the entry points.
Does picking a framework change how I talk to HTTP?
The wire is still HTTP. Frameworks wrap fetch, routers, and middleware. Libraries such as axios or got are called from your code. See what is HTTP for the protocol; see what is an API for the contract above it.
Sources
- MDN: Introduction to web APIs (libraries vs frameworks), accessed 2026-12-03developer.mozilla.org
- Full Byte Developer: What is an APIfullbytedeveloper.com
- Full Byte Developer: What is HTTPfullbytedeveloper.com