@e-n-v/env 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ <!-- markdownlint-disable-next-line -->
2
+ <img src="./assets/env-logo.png" alt="e-n-v Logo" height="55"/>
3
+
4
+ > Environments, niftily? Very!
5
+
6
+ e·n·v is a suite of handy stuff for working with environment variables and `.env` files, including interactive setup and runtime validation.
7
+
8
+ ```ts
9
+ // Define environment variables
10
+ const model = define({
11
+ schemas: { NODE_ENV, DATABASE_URL, PORT },
12
+ });
13
+ ```
14
+
15
+ ```ts
16
+ // Set up during development
17
+ await prompt(model); // or use `e-n-v setup`
18
+ ```
19
+
20
+ ```ts
21
+ // Validate at runtime
22
+ const env = parse(process.env, model);
23
+ ```
24
+
25
+ <!-- markdownlint-disable-next-line -->
26
+ <img src="./assets/demo.gif" alt="Demo" width="500"/>
27
+
28
+ ## Usage
29
+
30
+ ### 1. Define your model
31
+
32
+ An env model defines the structure of your environment variables, including names, schemas, and any preprocessing (e.g. converting `1`/`0` to boolean). This model is used both for development-time setup and runtime validation. e·n·v provides built-in schemas for common variables, and custom schemas can be authored using Zod.
33
+
34
+ ```ts
35
+ // env.model.js
36
+
37
+ import { define, schemas } from "e-n-v";
38
+
39
+ const { NODE_ENV, DATABASE_URL, PORT } = schemas;
40
+
41
+ export default define({
42
+ schemas: { NODE_ENV, DATABASE_URL, PORT },
43
+ });
44
+ ```
45
+
46
+ ### 2. Set up for development
47
+
48
+ Run `e-n-v setup` to interactively author your local `.env` file during development. This can be wrapped in a package script, e.g. `npm run env`. (Alternatively, a `prompt` method is available for programmatic use.)
49
+
50
+ ### 3. Parse at runtime
51
+
52
+ In your app, load your environment variables as usual, parse them, and export them for use. A combined error is thrown if any variables fail validation. Reference these exports throughout your code rather than using `process.env` directly.
53
+
54
+ ```ts
55
+ // env.vars.js
56
+
57
+ import "dotenv/config";
58
+ import { parse } from "e-n-v";
59
+ import model from "./env.model";
60
+
61
+ export const { NODE_ENV, PORT, DATABASE_URL } = parse(process.env, model);
62
+ ```
63
+
64
+ ### 4. Customize
65
+
66
+ e·n·v provides a variety of customization options, including:
67
+
68
+ 1. Authoring custom variable schemas using Zod or built-in schema utilities.
69
+ 2. Reading and writing variables via other libraries, e.g. `dotenvx`.
70
+ 3. Changing the setup CLI behavior, such as what variables are treated as secrets.
71
+
72
+ Happy configuration!
Binary file
Binary file