Runing n8n from nodejs script make him crash

hi, i run nodejs script that run n8n the function body look like this:
const n8nProcess = spawn(‘C:/Program Files/nodejs/npm.cmd’, [‘run’, ‘start’], {
cwd: “c:\init\extracted/n8n”,
env: process.env,
stdio: ‘inherit’,
detached: true

my problem is the terminal is close and the last thing that he print is n8n start processing
it’s not happened all the time, it occurs half of the time.
i am using 0.213 version I want to avoid to upgrade version for now
I try:
set in the environment variable

also I try run it on a stronger machine it still happen
also I create new db file and make at least one run creation of the db file
after that 2 from 11 tries failed
also I try to remove the call from the script, and make the call from batch, and still the same

I would love to hear if anyone has a recommendation

Hey @Asaf_Shay,

If you can get the error that is outputted that would be very handy, I am not sure this is an issue with n8n itself though and it is likely to be how you are running it.

it’s crash when there is output “Initializing n8n process”

npm version 8.11.0

Is it crashing then or just closing? It could be that your spawn process is killing it early. If you run n8n in one of our supported ways does that work as expected?

what is supported way ?

basically, the terminal window is closed, I don’t know if it crashes or close by your definition
I check the log and there is nothing new

Hi, would running the n8n.cmd works? I’d register it as a service so it auto run with the windows.

thanks i will check it

i try it, it’s work but the problem is that I can’t see workflows that I importing using the cli
and I see them in the database, and also when I run n8n using “npm run start” from the command line in n8n folder I can see the workflows, so what happened here? why there Is difference between run n8n from the command line and through process ?

i set new process with nssm and I notice that he save a new workflow in
and I need to point him to here

so I add in nssm environment variable like this

but it look like he ignores from that and still show to me the workflow from

how can I fix it ?



Hi, had checked my system and the .n8n folder exists only my userprofile and not under systemprofile. I didn’t define any environment variable in nssm, but you may try to set it as system variable, as I’d set any n8n env variable there.

If that doesn’t worked, another option is to run n8n using cli then export both the workflows and credentials. After that start n8n as service and import them back in. Do note your workflow number may changed.

i set more env variable in nssm doesn’t work

when i import workflow i need to run it from command line so i try running it from
but still it imported the workflows to the database that in

i try also install n8n -g
and i imported the workflows but still i can’t see them in the gui
i think that i only need to know how to point the n8n that run from the procees to point the diffrent database file

That is to be expected, We will add the workflows to the default database path. If you are trying to run n8n in an unsupported way you will run into problems like this.

Did you try setting N8N_USER_FOLDER and pointing it to the .n8n folder in the users home folder or if you are running as a Windows service with a named user you could run the cmd prompt as that user to do the import. If you are using local system you will have some issues.

hi, The problem was in the beginning that the n8n crashed, As you can see, I tried many things, and in the end, what solved the problem was a version upgrade (to 0.233), the problem is that every few months you have to upgrade, and this means that the system cannot function in production, because if customers work with the system at any point it will stop working until the version is upgraded, what can be done?

Hey @Asaf_Shay,

I don’t think we ever got to the bottom of the issue at the start before this got out of hand :slight_smile:

I am still not fully sure on what you are actually trying to do and why using an easier option like NPM or Docker won’t work for you. I think at this point it would probably be quicker to take a more supported route.

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