Purchase Option Extension environment

Solved
HunkyBill
Shopify Expert
4843 60 546

Inside the Shopify-rendered code for this extension, how can we tell if we accessing it via a development session or a live production session? Is there a way to know? What is the most common pattern for this? We write one version of the code, and it has to function in both a development sense and a production one.

process and process.env as common ways to handle this do not exist in the Shopify extension, so what do people do?

 

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
Accepted Solution (1)
ElanaK
Shopify Staff
Shopify Staff
15 4 3

This is an accepted solution.

Since the extension isn't a actually running in a Node environment, `process.env` doesn't quite work out of the box, but our CLI team has used made it possible to use the `process.env.SOME_VAR` syntax in your code to access environment variables from a `.env` file. So, you can't access the whole `process.env` object (it doesn't actually exist in an extension), but if you add  `MY_ENV` or something like that to an `.env` file and then use `process.env.MY_ENV` in your code, you can get your environment (and any other environment variables you set in the same way). Hope that helps!

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Reply 1 (1)
ElanaK
Shopify Staff
Shopify Staff
15 4 3

This is an accepted solution.

Since the extension isn't a actually running in a Node environment, `process.env` doesn't quite work out of the box, but our CLI team has used made it possible to use the `process.env.SOME_VAR` syntax in your code to access environment variables from a `.env` file. So, you can't access the whole `process.env` object (it doesn't actually exist in an extension), but if you add  `MY_ENV` or something like that to an `.env` file and then use `process.env.MY_ENV` in your code, you can get your environment (and any other environment variables you set in the same way). Hope that helps!

To learn more visit the Shopify Help Center or the Community Blog.