npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expo-env

v1.1.1

Published

Multiple environment solution for Expo based React Native apps

Downloads

2,011

Readme

expo-env

.env solution for React Native apps Built with EXPO

Expo does not give us much in terms of managing multiple environment based configuration. Atleast other than production and development. To overcome that, this is simply a workaround until a proper support is released by good folks at Expo.io.

How it works

  • Expo passes the options available in app.json file at the root of your React Native application, along with some other details, called as manifest and can be accessed by Expo.Constants.manifest
  • We simply use this to pass our environment based variables and configuration using the extra field inside that manifest.
  • We create a new app.json file reading the [environment].config.js file and passing it within that extra parameter.

What it involves

  • Firstly we would need to make our app.json to not be pushed to version control (i.e git), because whenever we will change our environment, we would be updating this file, so it will not make much sense to check this into you repository.
  • You will also create a configuration file for each of the environments you have. For ex. if you have staging, production and dev environments, you would create 3 files named staging.config.js, production.config.js and dev.config.js
  • Every time there is a need to change the env we would simply run this module so that it injects proper options within app.json, and then restart our packager using either exp CLI or through the XDE GUI tool.

Making it more seamless

  • TO make it more seamless, we can simple add these as npm scripts in our Expo app's package.json, such as:

package.json

  ...
   "scripts": {
     ...pre existing scripts,
     "env": "expo-env --env=development",
     "env:prod": "expo-env --env=prod"
   }
  ...

sample config file - i.e staging.config.js

module.exports = {
  "endpoint": "https://some-endpoint.someapi.com",
  "AWSKey": "Avsgvdye523"
}

You would be getting the above config/ENV vars inside your application if you use Expo.Constants.manifest.extra to get those values.

Options / Arguments

  • --env=[env]: Specifies the environment config to be picked up. (default: development)
  • --configPath=[path]: The path to all the env files. for ex. --configPath=./config will look into the config folder. (default: ./)
  • --template=[templatename]: The Name postfix for the env files. i.e [env].[templatename]. If values passed is .env.js it will look for [env].env.js in the configPath. (default: config.js)

Thank You!