cseelus
cseelus

Reputation: 1679

Read app.json (or exp.json) programmatically

Is there a way to read the contents of app.json programmatically from within you app, so you could for example get the current version number and show it within an About screen?

Upvotes: 29

Views: 16061

Answers (9)

Giga Meta
Giga Meta

Reputation: 319

For expo SDK 52:

import * as Constants from "expo-constants";

console.log(Constants.default.expoConfig?.version);

Upvotes: 0

Rahul Tiwari
Rahul Tiwari

Reputation: 372

Constants.manifest got deprecated now, you can access this through Constants.expoConfig. This includes your app.json config without any of the potentially sensitive information such as API secret keys.

import Constants from 'expo-constants';
Constants.expoConfig.version

Upvotes: 8

nvbach91
nvbach91

Reputation: 186

As of Expo SDK 46, use Constants.expoConfig. Source: https://github.com/expo/expo/discussions/17176

Upvotes: 4

Jay
Jay

Reputation: 338

npm:

npm install expo-constants

OR

expo:

expo install expo-constants

About.js

import Constants from "expo-constants";

<Text>Version {Constants.manifest.version} </Text>

Upvotes: 3

brentvatne
brentvatne

Reputation: 8038

You can access this through Constants.manifest. This includes your app.json config without any of the potentially sensitive information such as API secret keys.

import Constants from 'expo-constants';
Constants.manifest.version 

Upvotes: 66

Milean
Milean

Reputation: 888

For Expo SDK 35, I did this:

expo install expo-constants

in your .js:

import Constants from "expo-constants";

<Text> {Constants.manifest.description} </Text>

Upvotes: 5

Adam Diament
Adam Diament

Reputation: 4860

Newer versions of expo (I'm on 36) now import the variable differently

import Constants from 'expo-constants';

Read all about it here on the expo documentation site

Upvotes: 1

knot22
knot22

Reputation: 2768

When trying to use this line

import { Constants } from 'expo-constants';

Constants was showing up as undefined when logged to the console.

However, this code worked to display the app's version:

<template>
  <text>version: {{ appVersion }}</text>
</template>

<script>

import * as Constants from 'expo-constants';

export default {
  data() {
    return {
      appVersion: Constants['default']['manifest']['version']
    }
  }
}
</script>

Upvotes: 0

Arvindlal Jaiswal
Arvindlal Jaiswal

Reputation: 257

For expo SDK 33 use:

 import Constants from "expo-constants";
 {`v${Constants.manifest.version}`}

Upvotes: 3

Related Questions