Giter VIP home page Giter VIP logo

denv's People

Contributors

crowlkats avatar halvardssm avatar srnv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

denv's Issues

Undefined when space exists between the key and the = sign

Environment

deno 1.0.0
v8 8.4.300
typescript 3.9.2

undefined is return when trying to access a value that has a space between it's key and the = sign.

// .env
Current behavior

name =my name is meeky // returns undefined
name = my name is meeky // returns undefined

Expected behavior

name =my name is meeky // returns my name is meeky
name = my name is meeky // returns my name is meeky

Proposed fix:
a simple trim() will fix this issue in file mod.ts on line #24

Deno.env.set(key.trim(), val.trim()); // works fine

How I'm using denv

Hello, just wanted to share how I am using this in case anyone else is trying to figure out how to implement something like NODE_ENV with cascading ".env" files.

With this example I can have a .env file for production values and a .env.local which is gitignored, for override. Also a .env.development file for default development environment and a gitignored .env.development.local for override again.

I am new to Deno and top-level awaits, so I'm not sure great that is to have here but at the least, we should probably put an error handler in for it... The loadEnv imported here is load from https://deno.land/x/[email protected].

import { loadEnv } from "./deps.ts";

/** NOTE: We are in `production` by default! Set APP_ENV via CLI for others. */
export type ConfigEnvironments = "development" | "production";

const APP_ENV: ConfigEnvironments =
  (Deno.env.get("APP_ENV") ?? "production") as ConfigEnvironments;

const pathToEnvFile = APP_ENV === "development" ? ".env.development" : ".env";

await loadEnv({
  // Try the ".local" file first.
  path: pathToEnvFile + ".local",
  // Don't overwrite variables set in the CLI.
  priorityEnv: false,
  ignoreMissingFile: true,
  verifyAgainstExample: false,
  // If a ".local" file doesn't exist, try a non ".local" file.
  defaultToExample: true,
  exampleFile: pathToEnvFile,
});
// CONSIDER: Could also call loadEnv twice, to overwrite variables the 2nd time.
// TODO: Catch errors on calls to loadEnv and log/print them.

const { env } = Deno;

export const config = {
  /** NOTE: We are in `production` by default! Set APP_ENV for development. */
  APP_ENV,
  FOO: env.get("FOO") ?? "",
  PORT: Number(env.get("PORT")) || 8601,
  USER: env.get("USER") ?? "",
};
export default config;

More explicit message when file not found

Is it possible to have a message when the file was not found?

Actually, when the file is not present, we only get:

error: Uncaught NotFound: Le fichier spécifié est introuvable. (os error 2)
    at unwrapResponse (rt\10_dispatch_json.js:25:13)
    at sendAsync (rt\10_dispatch_json.js:76:12)
    at async open (rt\30_files.js:52:17)
    at async Object.readFile (rt\40_read_file.js:15:18)
    at async mod.ts:29:1

And I had no way to find out that it was coming from a missing .env or even denv.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.