當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。