@acai/config 中文文档教程
Açai Config Module
Açai 配置模块是一个小工具,可帮助您处理应用程序内部的数据。 默认情况下,它导出一个全局配置,以及一个创建作用域配置的选项。
Usage
import config from "https://deno.land/x/acai_config/mod.ts";
// access your env variables with
console.log(config.env);
// or
console.log(config.getEnv("key"));
// you can access your config with
console.log(config.config);
// or
console.log(config.getConfig("key"));
// you can also set a config with
config.setConfig("key", "value");
如果您希望将环境变量与配置变量绑定,您可以调用 config.fetchEnv(undefined, true)
,这会将所有环境变量存储在配置中。
Optional envs
默认情况下,config 会尝试从 .env
获取,但您可以传递一个预设来尝试。 如果找不到,它将在控制台上发出警报并尝试获取 .env。
import config from "https://deno.land/x/acai_config/mod.ts";
// will fetch env from .env.testing
config.fetchEnv("testing");
// will fetch env from .env.production
config.fetchEnv("production");
Açai Config Module
Açai config module is a small tool that helps you handle data inside of your application. It exports a global config by default, and an option to create a scoped config.
Usage
import config from "https://deno.land/x/acai_config/mod.ts";
// access your env variables with
console.log(config.env);
// or
console.log(config.getEnv("key"));
// you can access your config with
console.log(config.config);
// or
console.log(config.getConfig("key"));
// you can also set a config with
config.setConfig("key", "value");
If you wish to bind your env variables with your config variables, you can call config.fetchEnv(undefined, true)
, this will store all your env variables inside of the config.
Optional envs
By default, config will try to fetch from .env
, but you can pass a preset to try. If not found, it will alert on the console and try to fetch .env instead.
import config from "https://deno.land/x/acai_config/mod.ts";
// will fetch env from .env.testing
config.fetchEnv("testing");
// will fetch env from .env.production
config.fetchEnv("production");