crowlkats / denv Goto Github PK
View Code? Open in Web Editor NEWA module similar to dotEnv, but for Deno
License: MIT License
A module similar to dotEnv, but for Deno
License: MIT License
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
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;
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.