DEV Community

Discussion on: What is the difference between Library vs Framework?

Collapse
 
peerreynders profile image
peerreynders • Edited

For the same reasons I always feel like express is more library than framework.

1988 Johnson & Foote:

The methods supplied by the user tailor the generic algorithms defined in the framework for a particular application.

Looking at the express Hello World:

  • express() returns a generic express server.
  • app.get() "tailors" that generic server with user code - which will only be invoked by the express server.
  • app.listen() starts that generic server with the user code that "tailors" its operation ...

The framework often plays the role of the main program in coordinating and sequencing application activity

... which is exactly what app.listen() accomplishes. So express ticks all the boxes for a framework - while the main thread configures the generic server, once running, the generic server calls all the user code that was supplied via configuration.

It really comes down to:

  • If your code calls it, it's a library.
  • If it calls your code, it's a framework.

Off course by that definition the http module itself is a "framework" ...
node.js Hello world
... because the module "plays the role of the main program" and the module "calls the user code".

This just illustrates that a "framework" doesn't have to be big, complex or "all batteries included".

Some comments have been hidden by the post's author - find out more