当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dotenv.config函数代码示例

本文整理汇总了TypeScript中dotenv.config函数的典型用法代码示例。如果您正苦于以下问题:TypeScript config函数的具体用法?TypeScript config怎么用?TypeScript config使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了config函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: before

    before(function () {
        // Sets up environment variables from .env file
        dotenv.config();

        awsAccessKeyId = process.env["AWS_ACCESS_KEY_ID"];
        awsSecretAccessKey = process.env["AWS_SECRET_ACCESS_KEY"];
    });
开发者ID:bespoken,项目名称:bst,代码行数:7,代码来源:bst-encode-test.ts

示例2: envVarToConfig

export const makeConfig = props => {
  dotenv.config()
  const { prefix, noneString, envVars } = props
  const configWithNoneStrings = envVarToConfig({ prefix, noneString, envVars })
  const mandatoryKeys = readMandatoryEnvVarKeys()
  const missingKeys = mandatoryKeys.filter(
    makeFilterMissingKeys(configWithNoneStrings)
  )
  const mandatoryKeyMissing = missingKeys.length > 0
  const envVarKeysTooMany =
    Object.keys(configWithNoneStrings).length > mandatoryKeys.length

  if (mandatoryKeyMissing) {
    throw new Error(`Missing these env vars in config: ${missingKeys}.`)
  }

  if (envVarKeysTooMany) {
    throw new Error(`
      Config key count is ${Object.keys(configWithNoneStrings).length}.
      Mandatory key count is ${mandatoryKeys.length}.
      Config should not provide unused keys.
      Check your environment variables for any unused keys.
    `)
  }

  const config = Object.entries(configWithNoneStrings).reduce(
    (acc, [key, val]) => ({ ...acc, [key]: val === noneString ? null : val }),
    {}
  )

  return config
}
开发者ID:marcusnielsen,项目名称:mn-server,代码行数:32,代码来源:index.ts

示例3: constructor

 constructor() {
   let filename = ".env";
   if (process.env.NODE_ENV === "test") {
     filename = `.env.${process.env.NODE_ENV}`;
   }
   dotenv.config({
     path: path.resolve(process.cwd(), filename)
   });
 }
开发者ID:jonathan-patalano,项目名称:blog-api,代码行数:9,代码来源:config.service.ts

示例4: constructor

 constructor(filePath: string = null) {
   let config;
   if (filePath) {
     config = dotenv.parse(fs.readFileSync(filePath));
   } else {
     config = dotenv.config().parsed;
   }
   this.envConfig = this.validateInput(config);
 }
开发者ID:CaptainShisha,项目名称:REST-API,代码行数:9,代码来源:config.service.ts

示例5: constructor

    constructor(config: IAppConfig) {
        const envContent = dotenv.config({ path: path.resolve(config.appRootPath, '.env') });
        if (!envContent || !envContent.parsed) {
            throw new Error(`.env file could not be found at location "${config.appRootPath}/.env"`);
        }
        this.envConfig = envContent.parsed;

        this.appHomeDirPath = config.appHomeDirPath;
        this.appRootPath = config.appRootPath;
    }
开发者ID:pschild,项目名称:image-management-tool,代码行数:10,代码来源:config.service.ts

示例6: beforeAll

beforeAll(() => {
    dotenv.config();

    knx = knex({
        client: "pg",
        connection: `${process.env.DATABASE_URL}_test`,
    });

    Model.knex(knx);
});
开发者ID:zaeleus,项目名称:lp-api,代码行数:10,代码来源:setupTests.ts

示例7: config

    /**
     * Configuration
     *
     * @class Server
     * @method config
     * @return void
     */
    private config(): void {
        // Read .env file (local development)
        dotenv.config();

        // By default the port should be 5000
        this.port = process.env.PORT || 5000;

        // root path is under ../../target
        this.root = path.join(path.resolve(__dirname, '../../target'));

    }
开发者ID:nawalgupta,项目名称:angular2-socketio-chat-example,代码行数:18,代码来源:app.ts

示例8: env

export function env(key: string, fallback?: any, envPath?: string) {
  dotenv.config({ path: envPath ? path.resolve(process.cwd(), envPath) : path.resolve(process.cwd(), '..', '.env') });
  let response: any = false;
  try {
    response = resolve(functions.config(), key.toLowerCase().replace(/_/g, '.'));
    if (!response) {
      response = process.env[key];
    }
  } catch (error) {
    response = process.env[key];
  }

  return response ? response : fallback;
};
开发者ID:MadnessLabs,项目名称:MadnessEnjineer,代码行数:14,代码来源:Env.ts

示例9: Promise

    return new Promise((resolve, reject) => {

        dotenv.config();

        var cpuCount = opts.cpuCores || cpus().length;
        var stopForking = false;


        // if this is process
        if (cluster.isMaster) {

            var onClusterMsg = (msg) => {

                if (msg == "fork")
                    cluster.fork().on('message', onClusterMsg);

            };

            onClusterMsg('fork');

            cluster.on('exit', function (worker) {
                console.error('Worker %s has died! Creating a new one.', worker.id);
                if (!stopForking)
                    cluster.fork();
            });

        } else {

            Server.bootstrap(opts, cluster.worker, (err) => {


                if (err)
                    return reject(err);


                if (cluster.worker.id == cpuCount) {
                    resolve(cluster.workers);
                }
                else if (cluster.worker.id < cpuCount)
                    process.send('fork');

            });

        }


    });
开发者ID:vrwebdesign,项目名称:serendip,代码行数:47,代码来源:Start.ts

示例10: getConfig

export function getConfig(environment: any): Config {
  if (!config) {
    // El archivo .env es un archivo que si esta presente se leen las propiedades
    // desde ese archivo, sino se toman estas de aca para entorno dev.
    // .env es un archivo que no se deberĂ­a subir al repo y cada server deberĂ­a tener el suyo
    dotenv.config({ path: ".env" });

    config = {
      port: process.env.SERVER_PORT || "3500",
      logLevel: process.env.LOG_LEVEL || "debug",
      mongoDb: process.env.MONGODB || "mongodb://localhost/petdb",
      redisHost: process.env.REDIS_HOST || "127.0.0.1",
      redisPort: Number(process.env.REDIS_PORT || "6379"),
      jwtSecret: process.env.JWT_SECRET || "+b59WQF+kUDr0TGxevzpRV3ixMvyIQuD1O",
      passwordSalt: process.env.PASSWORD_SALT || "DP3whK1fL7kKvhWm6pZomM/y8tZ92mkEBtj29A4M+b8"
    };
  }
  return config;
}
开发者ID:maticorv,项目名称:mascotas2018_foro,代码行数:19,代码来源:environment.ts


注:本文中的dotenv.config函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。