Could we imagine store the worklfow in files for a "file-based" n8n?

Hello, and thank you for this great effort to make a soft like n8n.

I’m asking this question as a web developer, to make my workflow “flow” in all the environments we could have in a customer / product project.

For example, on a project, I could need a workflow. I make it, test it locally, then I want to test it on a staging environment.

Usually, I write code, commit it, push it on a GitLab instance for example, and use CI / CD to test it on another environment, staging for example.

How could I do this with n8n workflows, since they are stored in a database (SQLite / PostGreSQL or others). I’ve read that TypeORM is used behind, so maybe that’s not a good idea.

But I’m asking the question “how could we persist workflow” in a git-based workflow :wink: .
I know that we can export json, but I imagine another way, like the actual UI, that would save files instead of records in a database.

What do you think about the idea / needs ? Am I wrong in my way of thinking ? Is there already a way to do it ?

Thanks for your answer(s)

Welcome to the community @mdartic and great to hear that you apparently enjoy n8n!

Yes understand your use case and how that could be helpful. But even if it would be file-based you would still have to tell n8n that it would have to update the data. LIke for example re-read the workflows and activate the ones that are supposed to be activated or read the updated version of an already active one from the file system. So not sure if we have to go totally file-based for that. It is planned to offer a proper API for n8n which would then easily allow to add, read, update, remove, … workflows along other things. That would mean that something like you just explained could be easily achieved with n8n itself (would be simply a workflow).
To be honest that is already possible now by simply using the not-official n8n API, the one the editor-UI uses. Like for example:

# List of all workflows
GET http://localhost:5678/rest/workflows

# A specific workflow
GET http://localhost:5678/rest/workflows/1

But be aware that this API could change or move at any time and if you use it you would have to make sure every time you upgrade that it still behaves as expected.

Hope that is helpful.

Thank for your quick reply, it’s helpful :slight_smile:

I have to think again about this need, I’m not sure how to correctly handle the versioning of workflow, and if it’s a good idea by the way.
The API could be an interesting path for n8n, but at this point I’m not convinced it could help the versioning, unless we could have a script that extract the workflows from database (via API) in files for versioning them. Then we could deploy workflows in others environments, by removing/inserting workflows in the environment database (via API). Why not ?!

Another question, and I didn’t dig into n8n code (so be kind :-)), is the database layer absolutely linked at TypeORM ? Or did you make a separation layer that is like a “storage” layer, and could be “adapted”, for a database with TypeORM, or a file storage, and that could fit the first idea of a “file based n8n” ?

Thanks again

1 Like

Currently everything works through TypeORM. So to make it work you could write a “file-adapter” for it. Anyway think leaving n8n use a proper database and handling something like that via a workflow or script sounds currently like the better way.