Read the statement by Michael Teeuw here.
secrets.js
-
@rak You may wish to use
dotenv
. You can either do this on a module level, or for your local install.https://www.npmjs.com/package/dotenv
Here you would just make an
.env
file in your project root with something like:API_KEY=MySuperSecretApiKey1
Then you should be able to update the config file with:
var localConfig = require('dotenv').config(); var config = { ... { ... apiKey = process.env.API_KEY, }
Just make sure to add the
.env
file to.gitignore
so it won’t get committed via git. -
@mrmidi Thank you very much. This goes into the desired direction.
I have installed dotenv and added
var localConfig = require('dotenv').config();
If I do so starting the MM it shows missing config file.
Any ideas?
-
@rak This is most interesting :)
I am actually working on testing this now. There is no real reason this should not have worked, but you are 100% right, it seems to tank the config.
What’s really interesting is that I am tinkering around in the ./js/app.js file, and it’s actually not breaking when it’s being imported. The config file that comes in gets merged just fine and consoling it out, shows the correct
dontenv
getting replaced.This means somewhere else along the line, this code is breaking.
Hopefully I can follow the config through the app and detect where that’s happening and post back ASAP.
-
@rak OK, so after digging into this more, it looks like this won’t work without an update to the way the config.js file is loaded.
Currently, it is being loaded two ways.
- As an exportable module that can be used via
require()
statements - As vanilla javascript
So the
dotenv
would have worked fine ( and DOES work fine ) when used in a module context. However, the vanilla JS cannot reference module data this way. The solution would be to dig more into the./js/app.js
and./js/main.js
files and look at how they are handling theloadConfig
functions and see if there is not a way to tweak it for your purposes.Sadly, there is not much more I can think of to help with that without spending several hours tinkering around.
- As an exportable module that can be used via
-
@mrmidi I’m pretty sure the problem is, that the config file gets loaded in the browser. The browser doesn’t have require, it’s a nodejs feature.
https://github.com/MichMich/MagicMirror/search?q=CONFIG_FILE&unscoped_q=CONFIG_FILE
-
Hi!
I understand this issue. I use a gitlab private repository. I clone it in “magicmirror_config” in /home/pi/
And then I created a symlink im /home/pi/MagicMirror/config/ for my versioned config.jsAnd all my personalized files are in symlink where I need it.
That’s really easy and like that I can test on local device (my Mac) before put it on the raspberry Pi. :-)