Convert n8n workflows to code?

Hey guys! I’ve been using n8n cloud for a while now and I love the product!

The problem i’m having is testing, maintaining and managing multiple nodes as I used the number of people who need automations.

I want to know if I can convert my existing workflows to actual code (something like javascript or python) so I can commit them. Run robust tests. Follow software engineering best practices and the likes.

Do y’all have a guide or tutorial on how to write n8n workflows entirely in code and run it hosted with y’all?

Hi @hdotking :wave: We don’t have anything like that at the moment, so I’ve sent this over to the feature request section of the forums :slight_smile:

Can you go into a little bit more about why you’d want this? I’m sure the product team would love to hear a bit more about it!

I’m not sure if this would help, but you can also find the n8n repo here: GitHub - n8n-io/n8n: Free and source-available fair-code licensed workflow automation tool. Easily automate tasks across different services.


The no/low code capacity of n8n is awesome! But integrating and scaling this into robust software infrastructure requires thorough testing. This can be quite slow and tedious when n8n is not a part of our existing github tests, workflow and automations (i.e. our CI/CD pipeline).

We could 10x our ability to debug errors, scale this to multiple users, rollback when things break and ship with confidence if we had a (high-code?) version of our workflows in a git-friendly format :slight_smile:

1 Like

Don’t forget to vote yourself. :slight_smile:

1 Like

If we exported it as code though you would be testing the exported code and not what n8n would actually run so I am not sure if the convert to code option would actually be that useful for a CI/CD pipeline, Unless you are only planning to use n8n to create the code and only run it outside of n8n.

One thing you can do now though is run n8n from inside a github action, This would allow you to test your current workflows and if you are using the source control feature in theory your flows would already be in Git for other instances to pull from.

If you wanted an example of this you can see how we do this here:

1 Like

This is a super interesting direction!

Two questions come to mind.

  1. How does this work if i’m using n8n-cloud?
  2. My workflows rarely flat-out “fail” in the traditional sense (so not too sure if the if: failure() hook is appropriate).

Essentially i’d like to assert that a given test workflow has a specific output (say a code block should select a certain airtable ID after some business logic). If True then it passes the test, else it fails.

In production we use pytest to get the job done. Would this level of testing granularity be achievable with your suggested solution? If so i’d love to learn how :smiley:

Hey @hdotking,

As long as your workflows are in git it shouldn’t matter if you are using cloud but if you wanted the git features built in you would need the enteprise option outside of that you could make workflows to commit and pull.

I don’t see why it wouldn’t be possible, In your workflow when you come off from the business logic you could use a stop and error for a failure or if you wanted to get really fancy you could run a development environment of n8n and use something like selenium to automate browser testing to ensure the flows are working.

There are a few options really it just depends on how creative you want to be. I do think exporting workflows as code would be very useful for running a flow in a different location or something but you would then need a set of tests for that as well.

1 Like

As long as your workflows are in git
So right now I’m using n8n-cloud to drag and drop nodes to create and activate workflows. I have nothing from n8n in git and would like to change that.

With respect to git, what is possible with the Pro v.s. Enterprise plan? The pricing page and docs is a little lacking in this regard.

Hey @hdotking,

With any version of n8n you can save workflows to git by building a workflow, You can use the API to get the workflows then use the GitHub node to create files we have had users doing this for a very long time you can find a couple of templates below for inspiration which will need to be updated for the user management feature but you could also just use the n8n node.

When you go from Pro to Enterprise for Git you gain access to the version control feature which lets you push workflows, variables and credentials to git without having to mess around, You can find the docs for this feature here: Source control and environments | n8n Docs

1 Like

This would be a nice feature to go from no-code to code to add more functionalities. Basically using n8n as a means to create/visualize the schema of user workflow/data requests and then integrating more features through code

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.