Read the statement by Michael Teeuw here.
How to keep secrets out of config.js (server only)
-
@oscarbhm. no, not at the moment… i modified run-start.sh in 2.10 to support split mode (where electron isn’t available), but never tried this on mac. the chrome browser executable name is probably incorrect…
set serverOnly: “local”, in config.js to try it
-
You’re right, I forgot about the
if (typeof module !== undefined)check. It might work if you setelectronOptions: { nodeIntegration: true }in the config, but I haven’t tested it. -
what does that line below the modules actually do out of curiousity?
-
@BKeyport if this file is loaded into a module based application, then the interfacing approach (module.export) is created for this file/module…
-
@BKeyport Here’s a more detailed explanation for you and anyone who is curious.
The
if (typeof module !== "undefined") {}line checks if there is a global variable namedmodule. If there is, then we must be using a module system and we have to exportconfigusingmodule.exports = config;. If not, then we must be in the browser andconfigwill already be available to any other modules.In the browser, there is no concept of separate modules (a.k.a. files); script files are loaded in and simply concatenated one after the other. So if you load
config.jsand thenanother-file.js, theconfigvariable (var config = { ... }) will be available as a global variable inanother-file.js. Themoduleandrequirevariables are not defined.In more modern code with a module system, you have to export anything you want to use elsewhere, and import it in modules where you need it. Node.js uses
module.exports = ...to export and... = require("module-to-import")to import.
