Executing workflows dynamically and see the result in the ui

I have a program in nodejs that install the n8n that was downloaded from git, I want to execute workflow after I finish importing all my workflow so I use
n8n execute --id=4
but before that, I want to run
“npm run start” so I can see the workflow run, the problem was that when I use “npm run start” n8n wait until I press “o”, so I can’t run n8n execute --id=4 after that, how can accomplish my goals?

Hey @Asaf_Shay,

This isn’t really directly related to n8n, What you are after is how to run an npm command in the background.

Depending on your OS there are a few options, If you are on Linux you could run npm run start & which should do the job until you close the terminal window or you could use Screen, Nohup, PM2 or the quickest solution would be to open a new terminal window then run the command to import the workflow.

Unless you are running the npm run start command from inside your nodejs application which then changes things a lot and instead you would want to look at how to run a process from Node in the background which will likely involve something like the child process spawn option.

Hopefully this helps.

I use windows, and I use child process, but the result is shown to me in the command line, my question is can I open automatically the browser with a specific workflow and run it?

btw
I know how to open a browser with a specific URL using nodejs, but how can I make the workflow run?

Hey @Asaf_Shay,

That is a bit of a different question, It is only software so technically you could do it. You would first need to open a browser then use something that allows you to interact with the interface to select the Execute Workflow button.

It would probably be easier to just use the n8n command line interface to trigger the workflow until the public API feature is in place.

but if I use the CLI I can’t see the result in the UI (my goal) only in the cmd window,

BTW
let’s say that I run the workflow and when he gets to the middle I close the browser by mistake, how can reopen the browser and see the workflow that I started running?

Hey @Asaf_Shay,

If you need to see the result that is a bit trickier and the only option would be to either use browser automation or look in the execution history if you have execution logging enabled.

If you close the browser when it is in the middle of the workflow you may be able to find it in the execution list page.

what do you mean “browser automation”?
execution history = execution list page ?

BTW
the option that I found to open browser and run specific workflow with nodejs is :
const puppeteer = require(‘puppeteer’);

(async () => {
const browser = await puppeteer.launch({executablePath: ‘C:\Program Files\Google\Chrome\Application\chrome.exe’,headless: false});
const page = await browser.newPage();
await page.waitFor(1000); //callibrate as per your need
await page.goto(‘http://localhost:5678/workflow/4’);
await page.click(‘.workflow-execute-wrapper’);
await page.waitForNavigation();
})();

but I don’t like it, I hope you have different way

Hey @Asaf_Shay,

By browser automation I meant use something like Puppeteer / Selenium to control the browser, The other option would be to manually run the browser and capture what is happening in the network tab of the browser and reproducing that same request from your application.

Yes by execution history it would be the Execution List page which should give you the execution runs if you have them enabled in the settings for the workflow.

The solution you have is mostly the same thing I would do which solves the problem.