Environment variables in app.json
complete
Cedric van Putten
We are using some libraries which requires us to enter API keys in app.json. Right now there is no quick way of using environment variables, or at least, I can't find anything related to that in the docs. It would be really helpful for us if we can use environment variables in our app.json to avoid having to either hardcode or use a template-like tool to fill this file.
J
John Milner
It looks like you can do this now by creating an app.config.js which you can use to transform the app.json programatically using javascript however you like:
https://docs.expo.dev/workflow/configuration/
for example you app.config.js could look like this:
module.exports = {
api_key: process.env.MY_SECRET_API_KEY,
};
Then just .gitignore app.config.js (and maybe add a app.config.js.example to git so that other contributors dont get confused)
Wodin
complete
Chaddy Kumbirai Rungwe
Wodin: how do we use this? I cannot find any docs, please do assist?
Wodin
Chaddy Kumbirai Rungwe: Hi. Have a look at the example in the pull request: https://github.com/expo/expo-cli/pull/1524
Cedric van Putten
Looks like this feature request will be obsolete soon with the arrival of https://github.com/expo/expo-cli/pull/1342 🚀
Alex Russell
I think what you're both looking for, unless I'm mistaken, is
Expo.Constants.manifest
: https://docs.expo.io/versions/latest/sdk/constants#expoconstantsmanifest / https://docs.expo.io/versions/latest/guides/how-expo-works.html#expo-manifestAlex Russell
Ahh I feel I _am_ partially mistaken - I think Igor simply needs
Expo.Constants.manifest
, but it's likely Cedric (and thus the actual feature request here) is actually looking for a way to actually have placeholders in app.json
that read the environment at the time that the app.json
manifest is built into a given app (exp publish
, build or otherwise).Cedric van Putten
Alex Russell: Sorry for the extreme late reply. But yes, that's what I meant. Sentry requires an API token with the publish rights, right now I need to hardcode it into the manifest. I can't refer to any environment variable. This exposes the token also to everyone who has read access within the repository. If there is a way not to expose it, I would be very happy.
Igor Korsakov
I do it like this:
const appjson = require('./app.json');
...
use appjson.expo.ios.buildNumber