Libraries vs. Frameworks

Bobby Brennan
Sep 12, 2017 · 4 min read

In the world of programming, the difference between a library and a framework is often a source of confusion and debate. In general, the differentiating feature is a matter of control — frameworks dictate how your project will be structured, whereas libraries are building blocks that can be used anywhere. If we use the metaphor of architecture, libraries are bricks, and frameworks are, fittingly, the frame.

From Stack Overflow

Example: jQuery vs. AngularJS

To illustrate the differences between libraries and frameworks, let’s look at two important open source solutions for building interactive webpages — jQuery and AngularJS.

Prior to 2006, DOM manipulation was messy and error prone. Web developers who wanted any level of interactivity were stuck using decade-old JavaScript APIs which could never have anticipated the needs of Web 2.0. To solve these issues, John Resig released jQuery, a set of beautiful, simple abstractions for examining and updating the DOM. Suddenly, tasks that once required many lines of code could now be accomplished in a single line:

Example: Using jQuery to add a class to a set of elements

Importantly, jQuery had no requirements for how, when, or where it was used. It could be immediately incorporated into any webpage, without the need to modify existing code. It is effectively just a shorthand notation for executing common JavaScript patterns. This is what makes it a library, rather than a framework.

Fast forward another decade to 2017: web development is going through a similar transformation with the emergence of MV* frameworks such as React and AngularJS. Like jQuery, they offer huge, time-saving abstractions for DOM manipulation. But unlike jQuery, they can’t be seamlessly incorporated into an existing project — as frameworks, they mandate how your code is structured and run.

For instance, one of the most useful abstractions in AngularJS is data binding — tying the value of some variable to what the user types:

This code automatically updates the “Your name is…” message as the user types, which would have previously required dozens of lines of vanilla JavaScript or several lines of jQuery. With AngularJS it’s achieved without any logic at all — just an HTML template!

The catch is that we can’t just add a <script> tag that pulls in AngularJS and start writing templates like this. The HTML needs to be part of an AngularJS component, which will parse it and generate the code we otherwise would have had to write ourselves. In truth, this minimal example requires dozens of lines of additional boilerplate before it will work.

Libraries and Frameworks at DataFire

With DataFire, our mission is to make your data easily accessible, no matter where it lives or what you want to do with it. We provide open-source integrations for over 500 different services, such as Slack, GitHub, and MongoDB, as well as a command-line tool for connecting them. But is it a library or a framework?

The answer is both. For each service we connect to, we provide a client library, available on npm. For instance, you can install the Reddit RSS library like this:

npm install @datafire/reddit_rss

And then use it in JavaScript:

Just like jQuery, you can use this anywhere you want Reddit data. Each of the 500+ DataFire clients can be incorporated into an existing codebase without modification.

But DataFire also provides a framework — a set of high-level abstractions for building, connecting, and triggering actions. If you’re looking to build an API or sync data between two services, the DataFire framework can help.

To use it, you need to install the DataFire command-line tool:

npm install -g datafire

Then, inside your project, create DataFire.yml:

Finally, start running your project:

datafire serve --port 3000

This is a toy example — it will simply serve content from Reddit’s r/gifs at localhost:3000/gifs — but you can use the DataFire framework to build more complex actions, run scheduled tasks, and more.

Conclusion: Tradeoffs and Control

There is a clear tradeoff when deciding whether you should be providing a library or a framework, and it all comes down to control.

Libraries offer the user a large amount of control, and have a low barrier to entry. They can be seamlessly incorporated into existing projects to add new functionality, and generally require little learning and boilerplate code to get started.

Frameworks are more powerful, but mandate how users organize their code. They are more likely to be used when starting a new project rather than incorporated into an existing codebase, and the developer will need to learn about the framework’s core concepts before they can start using it productively. But this inversion of control also helps developers avoid common errors, inefficiencies, and bikeshedding.

Overall, frameworks are more opinionated and libraries are more flexible. Both patterns of abstraction have their place in the world of programming, and while neither is inherently better, it’s important to determine which is appropriate for the problem you’re solving.

To learn more about DataFire, Check out the repo on GitHub, or visit

Blog for

Bobby Brennan

Written by

I’m a Software Engineer, specializing in Dev Tools, NLP, and Machine Learning

Blog for