Skip to content

getEnv ​

A função getEnv retorna o valor de uma variável de ambiente, com suporte a fallback caso não exista.

Sintaxe ​

typescript
getEnv(key: string, fallback?: string): string | undefined;

Parâmetros ​

NomeTipoDescrição
keystringO nome da variável de ambiente a ser obtida
fallbackstringValor alternativo caso a variável não exista (opcional)

Retorno ​

TipoDescrição
string | undefinedO valor da variável de ambiente, ou o fallback, ou undefined se nenhum existir

Exemplos ​

typescript
getEnv("NODE_ENV");
// => "production", "development", etc.

getEnv("INEXISTENTE", "valorPadrao");
// => "valorPadrao"

Notas ​

  • Suporta ambientes Node.js e Deno.
  • Retorna o valor do fallback se a variável não existir.

Referências ​

Released under the MIT License.