How can i stop and then restart the Node-Red application with runtime API?

I would like to close every flow and then restart them from the runtime API.
I am testing this code, but it crashes.

RED.start();

setTimeout(() => {

    console.log('RED starting to stop');

    RED.stop().then(() => {

      console.log('RED stopped');

    });

    setTimeout(() => {

      console.log('RED starting to start');

      RED.start().then(() => {

        console.log('RED started');

      });

    }, 15000);

  }, 15000);

I am getting the following errors.

> 22:40:00.924 ERROR [JS] TypeError: Cannot read property 'handleUpgrade' of null
>     at Server.upgrade (c:\dev\app\voc-builder-example-app\components\voc-builder\node_modules\@node-red\editor-api\lib\editor\comms.js:226:30)
>     at Server.emit (events.js:194:13)
>     at onParserExecuteCommon (_http_server.js:566:14)
>     at onParserExecute (_http_server.js:506:3)
> 22:40:01.068 INFO  [JS] TypeError: Cannot read property 'handleUpgrade' of null
>     at Server.upgrade (c:\dev\app\voc-builder-example-app\components\voc-builder\node_modules\@node-red\editor-api\lib\editor\comms.js:226:30)
>     at Server.emit (events.js:194:13)
>     at onParserExecuteCommon (_http_server.js:566:14)
>     at onParserExecute (_http_server.js:506:3)

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