本文整理汇总了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"];
});
示例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
}
示例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)
});
}
示例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);
}
示例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;
}
示例6: beforeAll
beforeAll(() => {
dotenv.config();
knx = knex({
client: "pg",
connection: `${process.env.DATABASE_URL}_test`,
});
Model.knex(knx);
});
示例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'));
}
示例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;
};
示例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');
});
}
});
示例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;
}