Can we do n8n deployment via command line?

Hi Jan and team,

Can we do a n8n deployment via command line ? let me know if anybody knows.
what about scallability in n8n ?

Thnaks in advance !!!

Hey @rajesh-kumar,

When you say deployment via command line what do you mean? Assuming you are using docker you would be able to just run the docker command and pass in all the options you require (you can find an example command here: Docker Installation | Docs)

When it comes to scaling there is a detailed installation page here: Scaling n8n | Docs that goes through the setup process that you might find useful.

Hey @Jon , Thanks.

         Yes , we are using docker for the deployment . my quest is , we are using credential for some workflow and its stored in SQLite manually . Instead of adding manually, Is there any other way to deploy the credential ? ( like command line )

Hey @rajesh-kumar,

That makes more sense, So you can’t add new credentials as such from the command line but you can export and import credentials (CLI commands for n8n | Docs) using the n8n cli options so you might be able to use the decrypted passwords option to see what the credentials export would look like and then import them into another instance.

If you did use the encrypted option you would need to make sure that each instance uses the same encryption key this would assume you just want to import backed up credentials as needed.

1 Like

I’d like to have a textual representation of all workflows in a directory, that I could pull from and push to the n8n instance, and keep versioned in git.

Also I’d like to deploy function nodes code with npm run deploy command

Hey @mattesilver,

You could do the first part with the CLI tool, you could export all workflows then commit and also pull from git and import into n8n.

When you say deploy function node code with npm what do you mean? The code in a function node would be in the json file from the export so you could in theory create something that would update the code in the json then import it but I have a feeling you might be after something else like maybe shared function nodes that work a bit like the credentials and you can select a function “template” from a list and manage them from one place.

You could do the first part with the CLI tool, you could export all workflows then commit and also pull from git and import into n8n.

Great news, I’ll look into it.

When you say deploy function node code with npm what do you mean?

So I have all my functions in one nodejs project, each workflow as a directory, code for each node in a separate file, plus some common files, mostly type declarations for TypeScript.

My code look more or less like this:

import * as dateFns from 'date-fns'; // example external dependency, added to n8n, and excluded from bundling
import {Input, Output} from './model';

declare const item: Input;

function main(item: Item):Output{
// the actual code
}

(function(
return main(item);
))()

Then, the build process is
npm run build

  1. open my js file in dist/
  2. copy its contents
  3. paste it in the node
  4. remove the anonymous function wrap, so it just calls return main(item)

I have

  • versioning
  • unit tests
  • dependency resolution
  • shared code (type declarations)
  • TypeScript
  • local IDE

but the deployment process is awful :confused:

Looking at that process it may be quicker to automate the steps have as part of your build process. The 4 steps after your build could be done with a script and you can pop it in the node json then at the end of it use the cli to import the workflow.

It isn’t pretty behind the scenes but it would solve your issue and would be potentially be quicker than planning out a full solution that would work for everyone.

The other option could be to build a custom node then you can select the function you want in your workflow and update that custom node with your own build process.

I guess it all comes down to what you would prefer to do, it would be worth opening a feature request for the last part of your process though.

1 Like

Hm, exactly which command exports workflows?

The first one here: CLI commands for n8n | Docs

Ah, I see. the help got me confused.

$ npx n8n --help
...
  export  Export credentials
  import  Import credentials

Thank you

1 Like

That looks like it could do with a bit of a tweak :slightly_smiling_face:

1 Like