Framework vs Library โ What's the Difference?
As you learn coding, the words "framework" and "library" keep coming up. Express is a "web framework," jQuery is a "library," and React is... officially a "library" but "used like a framework."
What's actually different?
Lab Analogy: Kit vs Reagent
Library = Individual Reagent
Think of Bradford assay reagent. When you need protein quantification, you take it out and use it; when you don't, it stays in the fridge. You design the experiment workflow, and the reagent appears in just one step.
Libraries in code work the same way:
const axios = require("axios");
const response = axios.get("https://api.example.com/genes");You're using the axios library by calling it when you need it. You decide the overall program flow.
Framework = Experiment Kit (Protocol Included)
Think of an ELISA kit. Inside the kit are a 96-well plate, antibodies, buffer, and wash solution, and you must follow the prescribed protocol. Step 1: coating โ Step 2: blocking โ Step 3: add sample... Change the order and you won't get results.
Express works the same way:
const express = require("express");
const app = express();
app.get("/samples", function(req, res) {
res.json({ message: "Sample list" });
});
app.listen(3000);Within the structure defined by the Express framework, you only write the parts you need to fill in (what to respond at the "/samples" route). You put your code inside the app.get() template โ you're not designing the entire HTTP request handling flow yourself.
Core Difference: Who Calls Whom
| Library | Framework | |
|---|---|---|
| Control | I write code and call the library when needed | Framework manages the overall flow and calls my code |
| Analogy | I pick up and use the reagent | The kit protocol guides me |
| Code pattern | library.function() โ I call it | Framework calls my function |
| Freedom | High (combine however you want) | Lower (work within defined structure) |
In software engineering, this difference is called "Inversion of Control." With libraries, you hold the control; with frameworks, the framework holds control and calls your code at the right moment.
When you write app.get("/samples", function(req, res) { ... }) in Express โ you don't execute this callback function yourself. When someone accesses /samples, Express calls this function for you. That's the "framework calling you" structure.
Classifying What We've Learned
| Name | Classification | Reason |
|---|---|---|
| Express | Framework | Express manages the request-response flow. Your code is inserted as callbacks |
| React | Library (official) | Handles only UI rendering. Routing/state management are separate choices |
| mysql2 | Library | You call it when you need DB connections |
| Next.js | Framework | Next.js manages file structure, routing, and builds |
React is officially a "library." But when used with Next.js, it behaves like a framework. This boundary isn't always clear-cut.
Why Use Frameworks?
"If they limit freedom, why use frameworks?"
Consistency โ If 10 team members each build servers with different structures, maintenance becomes impossible. When a framework enforces structure, anyone's code follows similar patterns and can be read the same way.
Eliminating repetition โ Implementing routing, error handling, and middleware from scratch every time wastes time. Use what the framework already provides.
Proven design โ It's a structure used and tested by tens of thousands of developers worldwide. Fewer bugs than something you designed alone.
It's the same in experiments. You could create your own custom assay, but using a validated kit makes results more reliable and easier for other researchers to reproduce.
Conclusion: In One Sentence
A library is "a tool you call," and a framework is "a system that calls you."
Remember when you put a callback in app.get() with Express? It wasn't you who executed that callback โ it was Express. That's a framework.