I'm having issues keeping my node child process alive. I have one complex webserver running express in a typescript file index.ts
// index.ts
const app = express();
...
app.get("/path", doStuff())
I am able to spawn a fork of the file in a child process using a test file
// test.spec.ts
import { spawn, fork } from "child_process";
describe("do test",()=>{
it("do stuff", async ()=>{
const instance = spawn('ts-node', ['path/to/index.ts'],{
cwd: 'path/to/workind/directory'});
});
console.log('#1',instance);
await new Promise(r => setTimeout(r, 60000));
console.log('#2',instance);
... // do stuff
});
});
Now my issue is that I can't run all the tests as I only have a few seconds before the instance gets killed. In console log #1 everything looks fine but at #2 it's already destroyed after 60 seconds. When waiting to completely start up and running the tests I would need at least 15min of instance running without interruptions.
I tried it with fork instead of spawn already and plenty of spawn/fork parameters such as detached
, silent
and stdio
.
Any idea what to do to keep it alive?
Thanks in advance :)