The Hooks API provides a way to insert custom code into certain key points of the runtime operation.
Note: there is also a hooks api in the editor, but it is less mature so not currently documented for general use.
RED.hooks
API
RED.hooks
APIRegister a new hook handler.
The hookName
is the name of the hook to register the handler for.
It can be optionally suffixed with a label for the hook - onSend.my-hooks
.
That label can then be used with RED.hooks.remove
to remove the handler.
When invoked, the hook handler will be called with a single payload object - the details of which will be specific to the hook.
The handler can take an optional second argument - a callback function to call when the handler has finished its work.
When the handler finishes its work it must either:
Any modifications it has made to the payload object will be passed on.
If the handler wants to stop further processing of the event (for example, it does would not want a message to be passed to the next node in a flow), it must either:
false
(strictly false
- not a false-like value)false
false
.If the handler encounters an error that should be logged it must either:
If a function is defined as the two-argument version (accepting the callback function), it must use that callback - any value it returns will be ignored.
RED.hooks.add("preDeliver.my-hooks", (sendEvent) => {
console.log(`About to deliver to ${sendEvent.destination.id}`);
});
Remove a hook handler.
Only handlers that were registered with a labelled name (for example onSend.my-hooks
) can be removed.
To remove all hooks with a given label, *.my-hooks
can be used.
RED.hooks.remove("*.my-hooks");
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy