zetachang / react-native-dotenv

A Babel preset let you import application configs from .env file (zero runtime dependency)
MIT License
915 stars 68 forks source link

Access `.env` vars from `package.json` scripts #49

Open mischlecht opened 6 years ago

mischlecht commented 6 years ago

Is there any way I can access my variables from the .env file in order to utilize them in my package.json scripts?

I'm attempting to store an API_KEY in the .env file and then pull it into a script in order to publish some bundles + source maps to Bugsnag.

If possible, I'd love to not have to hard code this API key in the script itself.

I've attempted the following script in my package.json file:

"get-api-key": "node -p \"require('react-native-dotenv')\""

and, when run, have received the following output:

> MediShareMobile@1.2.2 get-api-key /Users/michaelschlecht/Documents/dev/mediShareMobile
> node -p "require('react-native-dotenv')"

[Function]
MS-MBP-CCM:mediShareMobile michaelschlecht$

Any ideas how I can access variables in my .env file?

zetachang commented 6 years ago

You can simply require “dotenv“ lib, and access var from process.env.

Michael Schlecht notifications@github.com 於 2018年8月17日 週五 上午7:17 寫道:

Is there any way I can access my variables from the .env file in order to utilize them in my package.json scripts?

I'm attempting to store an API_KEY in the .env file and then pull it into a script in order to publish some bundles + source maps to Bugsnag.

If possible, I'd love to not have to hard code this API key in the script itself.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/zetachang/react-native-dotenv/issues/49, or mute the thread https://github.com/notifications/unsubscribe-auth/AAzRJSuTc65TYioiXvjXQVpOrWUVJYifks5uRf2CgaJpZM4WAuSD .

reemtariqq commented 5 years ago

can I change it from package.json command?