# All files / src config.js

0% Statements 0/12
0% Branches 0/10
0% Functions 0/2
0% Lines 0/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38

     import dotenv from "dotenv";

    /**
     * init dotenv
     * priority: environment -> .env
     *
     * Available settings
     *
     * APP_PORT=9527
     * APP_BASE_PATH=/v1
     * APP_JWT_PUBLIC_KEY=`a public key string`
     */

    dotenv.config();

    /**
     *
     * @param {*} name envrionment name
     * @param {*} option option with { required, default }
     * @returns {*} value
     */

    export function env(name, option) {
      const value = process.env[name];

      if (option.required && !value) {
        throw new Error(`environment ${name} is required`);
      }

      return value || option.default;
    }

    /**
     * APP
     */

    export const STORE_BASE = env("APP_STORE_BASE", { default: "/store/v1" });