@robinpath/dotenv
v0.1.1
Published
Secure .env file management with key validation, path restrictions, and protected system variables
Readme
@robinpath/dotenv
Secure .env file management with key validation, path restrictions, and protected system variables
Why use this module?
The dotenv module lets you:
- Parse a .env format string into an object
- Convert an object to .env format string
- Read a .env file and load values into process.env (won't override existing or protected vars by default)
- Read a .env file and return as object without modifying process.env
- Get a value from a .env file by key
All functions are callable directly from RobinPath scripts with a simple, consistent API.
Installation
npm install @robinpath/dotenvQuick Start
No credentials needed — start using it right away:
dotenv.stringify $varsAvailable Functions
| Function | Description |
|----------|-------------|
| dotenv.parse | Parse a .env format string into an object |
| dotenv.stringify | Convert an object to .env format string |
| dotenv.load | Read a .env file and load values into process.env (won't override existing or protected vars by default) |
| dotenv.read | Read a .env file and return as object without modifying process.env |
| dotenv.get | Get a value from a .env file by key |
| dotenv.set | Set a key=value in a .env file |
| dotenv.remove | Remove a key from a .env file |
| dotenv.exists | Check if a .env file exists |
| dotenv.keys | Return all keys from a .env file |
| dotenv.expand | Expand variable references like ${VAR} in values (process.env fallback disabled by default) |
Examples
Convert an object to .env format string
dotenv.stringify $varsRead a .env file and load values into process.env (won't override existing or protected vars by default)
dotenv.load ".env"Read a .env file and return as object without modifying process.env
dotenv.read ".env.local"Integration with RobinPath
import { RobinPath } from "@wiredwp/robinpath";
import Module from "@robinpath/dotenv";
const rp = new RobinPath();
rp.registerModule(Module.name, Module.functions);
rp.registerModuleMeta(Module.name, Module.functionMetadata);
const result = await rp.executeScript(`
dotenv.stringify $vars
`);Full API Reference
See MODULE.md for complete documentation including all parameters, return types, error handling, and advanced examples.
Related Modules
@robinpath/json— JSON module for complementary functionality
License
MIT
