A middleware chain for plugins based only on async/await and dependency injections
- extremely simple: the API exposes only two function :
.use()
and.run()
! - chainability: isn't that obvious, it's a chain, so all calls can be chained onto the previous one !
- simple semantic: to succeed, all links of the chain must give back a result, a single exception and the chain is broken !
- dependency injection: give all of your plugins all the goodies they want (free logger, free context, free tools...) so that they will require less dependencies !
- recursivity: a chain can be given to another chain and become a single link in a new process
- tracability: the api enforces giving chains and plugins a name so that every single step of execution can be very traceable !
- no dependency: yep
There is a great deal of chain middlewares around there.
So why a new one ?
The answer to this question is quite simple : to go forward !, and to get rid of all the outdated libraries that were based on the callback(err, ..)
paradigm (otherwise known as callback-hell)
We think that this programmatic paradigm has served node.JS well (pretty well in fact as it radically redefined the asynchronous way of thinking for programmers), but now that a powerful replacement is available natively in the form of the async/await
statements, it's time to leave that past in the dust...
So, simply told : the chain middleware does not support the callback(err, what)
paradigm.
That's the other strongest motivation for this library : a lot of these other libraries totally forgot another key point of interest of using a middleware framework : the freebies !
I mean,
You'll need Node.js 8 or higher then, type in the console and in your project's directory :
npm install --save chain
or
yarn add chain
Now, let's write a simple program that (...)
const chain = require('chain')
// let's write the most simple chain
chain('hello', {ensurePluginName: false}).use(str => str + ' World').use(console.log).run('Hello')