/ check-env-variables.js
check-env-variables.js
 1  const c = require("ansi-colors")
 2  
 3  const requiredEnvs = [
 4    {
 5      key: "NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY",
 6      // TODO: we need a good doc to point this to
 7      description:
 8        "Learn how to create a publishable key: https://docs.medusajs.com/v2/resources/storefront-development/publishable-api-keys",
 9    },
10  ]
11  
12  function checkEnvVariables() {
13    const missingEnvs = requiredEnvs.filter(function (env) {
14      return !process.env[env.key]
15    })
16  
17    if (missingEnvs.length > 0) {
18      console.error(
19        c.red.bold("\n🚫 Error: Missing required environment variables\n")
20      )
21  
22      missingEnvs.forEach(function (env) {
23        console.error(c.yellow(`  ${c.bold(env.key)}`))
24        if (env.description) {
25          console.error(c.dim(`    ${env.description}\n`))
26        }
27      })
28  
29      console.error(
30        c.yellow(
31          "\nPlease set these variables in your .env file or environment before starting the application.\n"
32        )
33      )
34  
35      process.exit(1)
36    }
37  }
38  
39  module.exports = checkEnvVariables