# All files / server/src/config env.js

95.65% Statements 22/23
91.66% Branches 11/12
100% Functions 4/4
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    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
    28x

    28x
    1876x
    1680x
    1624x

    28x
    1904x
    1876x
    1876x
    1680x
    1624x
    1624x

    28x

    1596x

    28x
    28x
    1904x

    28x
     // Load them from the environment file if any
    require('dotenv').config({ silent: true });

    // Check if a variable is numeric even if string
    const is = {
      numeric: num => !isNaN(num),
      boolean: bool => /^(true|false)$/i.test(bool),
      json: str => /^[{[]/.test(str) && /[}\]]$/.test(str)
    };

    const type = str => {
      if (!str) return;
      Iif (typeof str !== 'string') return str;
      if (is.numeric(str)) return +str;
      if (is.boolean(str)) return /true/i.test(str);
      try {
        if (is.json(str)) return JSON.parse(str);
      } catch (err) {
        return str;
      }
      return str;
    };

    const env = {};
    for (let key in process.env) {
      env[key] = type(process.env[key]);
    }

    module.exports = env;