@robinpath/env
0.1.1Node.jsPublicSecure environment variable management with sensitive value redaction and protected system vars
Env
Secure environment variable management with sensitive value redaction and protected system vars
Package: @robinpath/env | Category: Other | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the env module when you need to:
- Get the value of an environment variable -- Use
env.getto perform this operation - Check if an environment variable exists -- Use
env.hasto perform this operation - Get all environment variables (sensitive values are redacted by default) -- Use
env.allto perform this operation - Delete an environment variable (protected system vars cannot be deleted) -- Use
env.deleteto perform this operation - Mark an environment variable as sensitive (will be redacted in env.all output) -- Use
env.secretto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
get | Get the value of an environment variable | The environment variable value, the default value, or null if not set |
set | Set an environment variable (protected system vars cannot be overwritten) | True if the variable was set |
has | Check if an environment variable exists | True if the variable exists, false otherwise |
all | Get all environment variables (sensitive values are redacted by default) | Object with all environment variable key-value pairs (secrets shown as ***) |
delete | Delete an environment variable (protected system vars cannot be deleted) | True if the variable was deleted |
secret | Mark an environment variable as sensitive (will be redacted in env.all output) | True if marked |
load | Load environment variables from a .env file (won't override existing or protected vars) | Number of new variables loaded |
Functions
get
Get the value of an environment variable
Module: env | Returns: string -- The environment variable value, the default value, or null if not set
env.get "NODE_ENV"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the environment variable |
defaultValue | string | No | Default value if the variable is not set |
set
Set an environment variable (protected system vars cannot be overwritten)
Module: env | Returns: boolean -- True if the variable was set
env.set "API_URL" "https://api.example.com"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the environment variable (must match [A-Za-z_][A-Za-z0-9_]*) |
value | string | Yes | Value to set |
has
Check if an environment variable exists
Module: env | Returns: boolean -- True if the variable exists, false otherwise
env.has "NODE_ENV"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the environment variable |
all
Get all environment variables (sensitive values are redacted by default)
Module: env | Returns: object -- Object with all environment variable key-value pairs (secrets shown as ***)
env.all
| Parameter | Type | Required | Description |
|---|---|---|---|
showSensitive | boolean | No | Pass true to show sensitive values unredacted (default: false) |
delete
Delete an environment variable (protected system vars cannot be deleted)
Module: env | Returns: boolean -- True if the variable was deleted
env.delete "OLD_KEY"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the environment variable to delete |
secret
Mark an environment variable as sensitive (will be redacted in env.all output)
Module: env | Returns: boolean -- True if marked
env.secret "SMTP_PASS"
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Name of the environment variable to mark as sensitive |
load
Load environment variables from a .env file (won't override existing or protected vars)
Module: env | Returns: number -- Number of new variables loaded
env.load ".env"
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | Path to the .env file |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
Environment variable name cannot be empty | Check the error message for details |
Invalid environment variable name: "...". Must match /^[A-Za-z_][A-Za-z0-9_]*$/ | Check the error message for details |
Cannot overwrite protected system variable: "..." | Check the error message for details |
Cannot delete protected system variable: "..." | Check the error message for details |
@desc "Get and validate result"
do
set $result as env.get "NODE_ENV"
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. List and iterate
Retrieve all items and loop through them.
@desc "Get and iterate results"
do
set $result as env.get "NODE_ENV"
each $item in $result
print $item
end
enddo
2. Multi-step Env workflow
Chain multiple env operations together.
@desc "Get, has, and more"
do
set $r_get as env.get "NODE_ENV"
set $r_has as env.has "NODE_ENV"
set $r_all as env.all
print "All operations complete"
enddo
3. Safe get with validation
Check results before proceeding.
@desc "Get and validate result"
do
set $result as env.get "NODE_ENV"
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.1 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/env
