JavaScript: Difference Between Module, Library, Package, API, Framework and Application

In this post we will determine what do these terms mean and how do they relate to each other in the context of JavaScript.

Module

An isolated piece of code performing a very specific functionality is called a module. Usually but not necessarily, the code is contained in a single file or grouped together in a directory. For example, the below can be called add, subtract, multiply, and divide modules:

//add.js

const add = (a, b) => {
    return a + b;
}

export {
    add
}
//subtract.js

const subtract = (a, b) => {
    return a - b;
}

export {
    subtract
}
// multiply.js

const multiply = (a, b) => {
    return a * b;
}

export {
    multiply
}
//divide.js

const divide = (a, b) => {
    return a / b;
}

export {
    divide
}

Inside the module, the implementation could contain any valid JavaScript code including classes, functions, arrays, objects etc.

Library

A library is a piece of reusable code that provides some well-tested functionality through a well-defined interface. It can contain one or more modules. From previous example, we could group together add, subtract, multiply, and divide modules in my-calculator library. A real example would be lodash.

Package

A package is the compiled form of the library for distribution. A package mostly contains the source code, distribution code, documentation, examples, executables, test suite, meta-data (such as version number) etc.

A package manager stores all the versions of the package in a compressed form in an online registry. For JavaScript, npm is the defacto package manager and registry.

The distinction between a library and its package could be understood by the following:

  • Lodash library.
  • The package of lodash.

Both library and package terms are used interchangeably in JavaScript community.

API

API stands for Application Programming Interface. The general explanation is that when two softwares communicate with each other through an interface, that interface is called API. In the context of JavaScript, it usually means one of or the combination of the followings:

  • Cloud/Backend APIs of the server
  • Browser APIs
  • Operating System Level APIs

Browser APIs and OS level APIs are specific to their runtime environments i.e. browser and Node JS respectively.

In addition to the above, API also means the interface a JavaScript library exposes through which we can use its code and the functionality it offers. From our above example from module, add, subtract, multiply, and divide are the APIs of my-calculator library.

SDK

SDK means Software Development Kit. In web terms, it is a set of tools provided by a third party vendor/service/application in major languages, including JavaScript, so that the developers can build features or applications with the help of it. The SDK abstracts away the underlying complexity and minor details of integrating these services, so that we don’t have to worry about the integration part and can just focus on the feature development. In short, SDK comes with plenty of benefits:

  • Abstraction of implementation details
  • Intellisense for code editors
  • Error handling
  • Documentation
  • Helper methods
  • More control over the environment the SDK is running in (such as cookie management)

Are JavaScript Library And SDK the same thing? It’s a superset subset relationship between the two. All SDKs are libraries, but all libraries are not SDKs. To be an SDK, the library must be provided by a third party vendor (or someone else on their behalf, like an open source project) to facilitate the integration with the services they provide.

Real world examples of JavaScript SDKs:

Framework

Framework is a collection of libraries and configurations put together in a basic structure/skeleton that can be used to build a software or application. Essentially, the framework tells you how and where to add your code about what, and then runs it for you. For example:

  • Express JS is a web framework built for Node JS. With the help of Express JS we create web applications (mostly backend APIs).
  • Create React App, or the skeleton code it generates, can also be considered a framework, as it provides a basic structure to develop React applications. (whereas, React JS is just a UI library).

Application or App

An application is a complex piece of software that a user or another software can interface with. In case of JavaScript, the apps could be backend, frontend, mobile (e.g. react native), desktop (like electron), or even embedded. It’s usually developed with a framework, and contains multiple libraries along with the business logic code written specifically for the app.

See also

When you purchase through links on techighness.com, I may earn an affiliate commission.