I new to fastify framework for node.js, and I'm asking for what is the exact use of fastify-plugin because I can't get the the idea behind it. I tried some code with or without the plugin and I can't notice the difference. except for some behavior like :
1- I can override the decorator I initiate and wrapped it with fastify-plugin.
2- I can use and share the decorator with other registered plugins.
The concept is this one:
register
call will create an encapsulated contextregister
+ fastify-plugin
will not create an encapsulated context: you will stay in the same context where the register
was calledAn encapsulated context you will use:
Here a visualization:
so, if you add an onRequest
hook in the root node (the blue one), all the routes will execute that hook.
if you add the onRequest
hook in the green one instead, ONLY the routes defined in that context will use that hook.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With