Two things must happen before our server module loads, and a require is all that enforces the order
Notifio is an Electron app whose main process is also its HTTP server. There is no child process: app.whenReady() fires, and then one line pulls an Express application into the same process the windows live in. That line is a require , inside a function, in a file where every other dependency is a top level import . It looks like an oversight, and it is load bearing. This post is about why,…
Notifio is an Electron app with the main process serving as its HTTP server. There is no child process, and the server loads due to a require statement inside a function at the top of the main.ts file. This order is crucial, as implicit initialisation order can be problematic if not properly managed. The two main constraints for the server module to load are: 1.
The PLAYWRIGHT_BROWSERS_PATH environment variable must point at the bundled browser, and 2. Writable directories must exist before the server loads. These constraints are satisfied by the order of the code, as require is a function call and import is not. If the file started with a static import, both the environment variable and directories would not be properly set, leading to potential failures deep within the module's structure.
The initDataDirs() function ensures the necessary directories are created, including a copy of the config.json file if it is missing. This setup is necessary before the server module loads, as other modules, such as the scraper and power monitor, also rely on the server's loadConfig() function, which requires a properly configured environment.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.