Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .env variable in npm script

In my .env I have the following variable:

SHOPIFY_STORE_URL=mystore.myshopify.com

Now I want to use this variable in a npm script:

  "scripts": {
    "shopify-login": "shopify login --store=SHOPIFY_STORE_URL",
  },

so $ npm run shopify-login should execute $ shopify login --store=mystore.myshopify.com

How can I achieve this?

like image 871
Cenasa Avatar asked May 16 '26 11:05

Cenasa


1 Answers

When you are on a linux/mac operating system - this should work:

# .env
SHOPIFY_STORE_URL=mystore.myshopify.com

my test case:

  "scripts": {
    "shopify-login": "source .env && echo $SHOPIFY_STORE_URL"
  }

your test case:

  "scripts": {
    "shopify-login": "source .env && shopify login --store=$SHOPIFY_STORE_URL",
  },
like image 196
madflow Avatar answered May 17 '26 23:05

madflow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!