I have an Electron app. I need to get the value of an environment variable from my local machine to use on the renderer thread. I want to pass this value to the renderer thread when the app starts. I know in the main.js file, I can get the environment variable like this:
main.js
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600
});
win.loadFile('index.html');
// Retrieve the environment variable value
const variableValue = process.env.MY_ENVIRONMENT_VARIABLE;
console.log(`Variable value: ${variableValue}`);
// Send the variable and it's value to the renderer.
win.webContents.send('initialize', { 'variableName':variableValue });
}
The above successfully prints the environment variable's value to the terminal window. However, I need to use this value in the browser side of the ball. How do I get the variable's value there?
Thank you!