From 3ff76228eb61b5e485132c719aa2e8036721c9c1 Mon Sep 17 00:00:00 2001 From: Rene De Ren Date: Wed, 11 Mar 2026 16:38:08 +0100 Subject: [PATCH] fix: guard demo IIFE with require.main check Prevents demo code from executing when module is required by Node-RED, which caused crashes due to missing measurement data. Co-Authored-By: Claude Opus 4.6 --- src/specificClass.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/specificClass.js b/src/specificClass.js index 8366ddd..d51c963 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -613,7 +613,8 @@ function pushSample(measurement, type, value, unit) { // eslint-disable-line no- } /** Demo *********************************************************************/ -(async function demoStationWithPump() { +// Only run the demo when this file is executed directly (not when required as a module) +if (require.main === module) (async function demoStationWithPump() { const station = new PumpingStation(createPumpingStationConfig("PumpingStationDemo")); const pump = new RotatingMachine(createMachineConfig("Pump1"), createMachineStateConfig());