env-safeguard 1.0.1 → 1.0.3

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.
Files changed (3) hide show
  1. package/README.md +11 -0
  2. package/index.js +16 -7
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,17 @@ npm install env-safeguard
12
12
 
13
13
  ---
14
14
 
15
+ ## Features
16
+
17
+ - Validate required environment variables
18
+ - Detect missing variables
19
+ - Validate data types (`string`, `number`, `boolean`)
20
+ - Generate `.env.example` automatically
21
+ - Clear and readable error messages
22
+ - Lightweight and easy to use
23
+
24
+ ---
25
+
15
26
  ## Usage
16
27
 
17
28
  ```javascript
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const dotenv = require("dotenv");
2
2
  dotenv.config();
3
+ const fs = require("fs");
3
4
 
4
5
  function checkEnv(envs) {
5
6
  const missingVars = [];
@@ -33,6 +34,8 @@ function checkEnv(envs) {
33
34
  if (missingVars.length !== 0 || mismatchedDataTypes.length !== 0) {
34
35
  console.log("\n❌ Environment validation failed");
35
36
  console.log("--------------------------------");
37
+ } else {
38
+ generateEnvExample(envs);
36
39
  }
37
40
 
38
41
  if (missingVars.length !== 0) {
@@ -52,14 +55,20 @@ function checkEnv(envs) {
52
55
  }
53
56
 
54
57
  console.log("");
55
-
58
+
56
59
  process.exit(1);
57
60
  }
58
61
 
59
- module.exports = { checkEnv };
62
+ function generateEnvExample(envs) {
63
+ let content = "";
64
+
65
+ for (let key in envs) {
66
+ content += `${key}=\n`;
67
+ }
60
68
 
61
- checkEnv({
62
- PORT: "number",
63
- MONGO_URI: "string",
64
- DEBUG: "boolean"
65
- });
69
+ fs.writeFileSync(".env.example", content);
70
+
71
+ console.log("✅ .env.example generated successfully");
72
+ }
73
+
74
+ module.exports = { checkEnv };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "env-safeguard",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A lightweight utility to validate environment variables and prevent runtime errors caused by missing or misconfigured .env values.",
5
5
  "author": "Ayantik Sarkar",
6
6
  "license": "MIT",