28

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?

cseelus
  • 1,447
  • 1
  • 20
  • 31

7 Answers7

66

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 
brentvatne
  • 7,603
  • 4
  • 38
  • 55
5

For Expo SDK 35, I did this:

expo install expo-constants

in your .js:

import Constants from "expo-constants";

<Text> {Constants.manifest.description} </Text>
Milean
  • 878
  • 9
  • 16
4

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

nvbach91
  • 166
  • 8
3

For expo SDK 33 use:

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

npm:

npm install expo-constants

OR

expo:

expo install expo-constants

About.js

import Constants from "expo-constants";

<Text>Version {Constants.manifest.version} </Text>
Jay
  • 308
  • 2
  • 10
1

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

Adam Diament
  • 4,290
  • 3
  • 34
  • 55
-1

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>
knot22
  • 2,648
  • 5
  • 31
  • 51