What is ExternalHooks?

Hi my friends. Hope you’re doing great.

I have a question:
What is ExternalHooks.ts file doing? For example in Server.ts file for creating new workflow or updating one it runs a hook like this:
this.externalHooks.run(‘workflow.update’, [newWorkflowData])

Could you please explain? Thank you very much.

1 Like

It allows to dynamically execute code external when something specific happens in n8n. Like in the above example every time a workflow gets changed.
That is currently undocumented and not officially released yet as it may still change in the future.

It gets currently used for example in n8n.cloud to enforce the limits and count workflow executions.


Thanks man, As always: you are awesome!

You are welcome! Thanks a lot! Have a great day and upcoming 2021!

1 Like

@jan Hey Jan, How are you doing?

Long time ago I questioned about external hooks. I’m wondering if this feature is available for developers to use. Do you have any documentation to read? if you don’t can you please show me some files to look at and learn from them.

My case is: I want to be notified when a workflow is created, I see something like this:
await this.externalHooks.run(‘workflow.create’, [newWorkflow]);

Does this line of code emits an Event? So Can I be notified somewhere else?


You need to create a js file that exports an object with the structure below. Then, when starting n8n you provide the env variable EXTERNAL_HOOK_FILES with the path to this js file. The example below covers the event workflow:create. But, you can define multiple hooks in the same file.

module.exports = {
  workflow: {
    create: [
      async function (options) {
         // do whatever you want here
          console.log('workflow created')

Thanks @RicardoE105 you helped a lot.