Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
env-dot-prop
Advanced tools
Get, set, or delete nested properties of process.env using a dot path
♻️ Get, set, or delete nested properties of process.env using a dot path
Coded with ❤️ by Simone Primarosa.
This package aim to let you access to your environment variables as if they were JavaScript object. See this guide to understand how to use this package to create a 12 Factor compliant configuration system for you app.
$ npm install --save env-dot-prop
const envDotProp = require('env-dot-prop');
// Let's assume process.env contains the following keys
process.env = {
FOO_BAR: 'unicorn',
'FOO_DOT.DOT': 'pony',
'FOO_UND\\_UND': 'whale'
};
console.log(process.env);
// => { FOO_BAR: 'unicorn', 'FOO_DOT.DOT': 'pony', 'FOO_UND\_UND': 'whale' }
envDotProp.get('');
// => { foo: { bar: 'unicorn', 'dot.dot': 'pony', und_und: 'whale' } }
// getter
envDotProp.get('foo.bar');
// => 'unicorn'
envDotProp.get('foo.notDefined.deep');
// => undefined
envDotProp.get('foo.notDefined.deep', 'default value');
// => 'default value'
envDotProp.get('foo.dot\\.dot');
// => 'pony'
// setter
envDotProp.set('foo.bar', 'b');
envDotProp.get('foo.bar');
// => 'b'
envDotProp.get('');
// => { foo: { bar: 'b', 'dot.dot': 'pony', und_und: 'whale' } }
envDotProp.set('foo.baz.e', 'x');
envDotProp.get('foo.baz.e');
// => 'x'
envDotProp.get('foo.baz');
// => { e: 'x' }
envDotProp.get('');
// => { foo: { bar: 'b', baz: { e: 'x' }, 'dot.dot': 'pony', und_und: 'whale' } }
// has
envDotProp.has('foo.bar');
// => true
// deleter
envDotProp.delete('foo.bar');
envDotProp.get('foo');
// => { baz: { e: 'x' }, 'dot.dot': 'pony', und_und: 'whale' }
envDotProp.delete('foo.baz.e');
envDotProp.get('foo.baz');
// => undefined
envDotProp.set('n1', 42, {stringify: false});
envDotProp.get('n1', {parse: false});
// => 42
envDotProp.get('n1', {parse: true});
// => 42
envDotProp.set('n2', 42, {stringify: true});
envDotProp.get('n2', {parse: false});
// => '42'
envDotProp.get('n2', {parse: true});
// => 42
envDotProp.set('n3', 42);
envDotProp.get('n3');
// => 42
envDotProp.set('n4', '42');
envDotProp.get('n4');
// => '42'
envDotProp.get('');
// => { n1: '42', n1: 42, n3: 42, n4: '42', foo: { 'dot.dot': 'pony', und_und: 'whale' } }
console.log(process.env);
// => { 'FOO_DOT.DOT': 'pony', 'FOO_UND\_UND': 'whale', N1: '42', N2: 42, N3: 42, N4: '42' }
any
Gets the values of environment variables at the path specified.
Kind: global function
Returns: any
- The values of environment variables associated with the path specified.
Access: public
Param | Type | Default | Description |
---|---|---|---|
path | string | Dot separated path. | |
[defaultValue] | any | Default value to return if there is not any environment variable that matches the path provided. | |
[opts] | Object | Additional options. | |
[opts.parse] | boolean | false | If true the value retrieved is converted to the proper type. |
[opts.caseSensitive] | boolean | false | If true no case conversion will be performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY. |
Sets an env key at the path specified. If nested keys are present they will be deleted.
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
path | string | Dot separated path. | |
value | string | Value to set. | |
[opts] | object | Additional options. | |
[opts.stringify] | boolean | false | If true the value provided is converted to string. |
[opts.caseSensitive] | boolean | false | If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY. |
Deletes an env key at the path specified. If nested keys are present they will be deleted too.
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
path | string | A dot separated path. | |
[opts] | object | Additional options. | |
[opts.caseSensitive] | boolean | false | If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY. |
boolean
Returns whether an env key exists at the path specified.
Kind: global function
Returns: boolean
- true if exists at least one environment variables with that
path prefix.
Access: public
Param | Type | Default | Description |
---|---|---|---|
path | string | Dot separated path. | |
[opts] | object | Additional options. | |
[opts.caseSensitive] | boolean | false | If true no case conversion is performed from the dot path provided to the env key search. Eg: 'tesT.kEy' will look for tesT_kEy environment variable instead of TEST_KEY. |
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the license file for details.
FAQs
Get, set, or delete nested properties of process.env using a dot path
The npm package env-dot-prop receives a total of 1,127 weekly downloads. As such, env-dot-prop popularity was classified as popular.
We found that env-dot-prop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.