How to use the dotenv-expand function in dotenv-expand

To help you get started, we’ve selected a few dotenv-expand examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eram / tensorflow-stack-ts / src / index.ts View on Github external
const env = process.env;
    setProcessHandelers(appGlobals);
    console.log("argv:", argv);

    if (!env.ROUTER_APP || !env.PORT) {

        // get config from environment: use "--resolve" to set the .env file
        console.log("loading env from .env", argv);
        let dotenv = Dotenv.config();
        if (dotenv.error) {
            console.warn(".env load failed. loading .debug.env");
            const fileName = path.resolve(process.cwd(), ".debug.env");
            dotenv = Dotenv.config({ path: fileName });
        }
        dotevExpand(dotenv);
    }

    if (!env.ROUTER_APP || !env.PORT) {
        console.error(`failed to load environment`);
        return 2;
    }

    console.log("env loded:", env);

    // get version from package.json
    const p = path.resolve(process.cwd(), "./package.json");
    try {
        const buf = fs.readFileSync(p);
        if (buf && isBuffer(buf)) {
            const pkg = JSON.parse(buf.toString()) as IndexSig;
            if (pkg && pkg.version) {
github parcel-bundler / parcel / packages / core / core / src / loadDotEnv.js View on Github external
dotenvFiles.map(async dotenvFile => {
      const envPath = await resolveConfig(fs, filePath, [dotenvFile]);
      if (envPath == null) {
        return;
      }

      // `ignoreProcessEnv` prevents dotenv-expand from writing values into `process.env`:
      // https://github.com/motdotla/dotenv-expand/blob/ddb73d02322fe8522b4e05b73e1c1ad24ea7c14a/lib/main.js#L5
      let output = variableExpansion({
        parsed: dotenv.parse(await fs.readFile(envPath)),
        ignoreProcessEnv: true
      });

      if (output.error != null) {
        throw output.error;
      }

      return output.parsed;
    })
  );
github evenchange4 / dotenv.macro / src / macro.js View on Github external
function dotenvMacro({
  references,
  babel: { types: t },
}: {
  references: { default: any },
  babel: { types: any },
}): void {
  // Note: Load dotenv file
  if (!cacheDotenv) {
    cacheDotenv = dotenv.config();
    dotenvExpand(cacheDotenv);
  }
  const { default: defaultEnvs = [], ...destructureEnv } = references;

  // Case 1: import env from 'dotenv.macro'
  defaultEnvs.forEach(referencePath => {
    if (referencePath.parentPath.type === 'MemberExpression') {
      const { name } = referencePath.parentPath.node.property;
      const value = process.env[name];
      referencePath.parentPath.replaceWith(valueExpression(t, { name, value }));
    } else {
      const parsedAst = Object.keys(cacheDotenv.parsed).map(name => {
        const value = (process.env: any)[name];
        return t.objectProperty(
          t.stringLiteral(name),
          valueExpression(t, { name, value }),
        );
github electron-userland / electron-webpack / packages / electron-webpack / src / main.ts View on Github external
return null
  }

  const processEnv = configurator.isProduction ? "production" : "development"
  const dotEnvPath = path.resolve(configurator.projectDir, ".env")
  const dotenvFiles = [
    `${dotEnvPath}.${processEnv}.local`,
    `${dotEnvPath}.${processEnv}`,
    `${dotEnvPath}.local`,
    dotEnvPath,
  ]

  for (const file of dotenvFiles) {
    const exists = await pathExists(file)
    if (exists) {
      dotEnvExpand(
        dotEnvConfig({
          path: file
        })
      )
    }
  }
  return await configurator.configure()
}
github atolye15 / web-starter-kit / gulp / utils / env.js View on Github external
dotenvFiles.forEach(dotenvFile => {
  if (fs.existsSync(dotenvFile)) {
    dotenvExpand(dotenv.config({ path: dotenvFile }));
  }
});
github RodolfoSilva / graphql-typescript-server-boilerplate / src / config / env.ts View on Github external
.forEach((dotEnvFile: string) => {
    dotEnvExpand(dotEnv.config({ path: dotEnvFile }));
  });
github eankeen / tails / dashboard-mpa / core / env.js View on Github external
import dotenv from 'dotenv'
import dotenvExpand from 'dotenv-expand'

const env = dotenv.config()
dotenvExpand(env)

dotenv-expand

Expand environment variables using dotenv

BSD-2-Clause
Latest version published 5 days ago

Package Health Score

85 / 100
Full package analysis

Popular dotenv-expand functions