Purchase Option Extension environment

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?

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!

1 Like

I can’t seem to get this to work. process.env.MY_ENV doesn’t get changed during build/dev with the cli and I get a console error process not defined in the browser.

Are there any examples I can reference?