
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
dotenv-helper
Advanced tools
Library for better use of environment variables.
If you prefer holding environment variables in a file in your root project directory, then you should use dotenv library.
If you want to make CRUD request to this file, then dotenv-helper might be a better choice, than dotenv.
This library contains already the dotenv library, so you shouldn't use both libraries together.
Run npm i dotenv-helper to install the library
Create .env file in your root project directory
Write your first environment variables in the .env file, such as:
NODE_ENV=production
PORT=3000
Now you can use those environment variables, such as:
const env = require("dotenv-helper")
const port = env.getEnv("PORT") // => "3000"
But if you need only that, then dotenv library is good enough for you.
Here is what dotenv-helper gives you:
const env = require("dotenv-helper")
let foo = env.getEnv("foo")
if(foo===false){
foo = "bar"
env.addEnv("foo","bar").then(console.log)
}
We check if there is a foo enviroinment variable.
If foo is false, this means that there is no such variable in the .env file.
Now we set foo = "bar", as we need that for our code to work, and afterwards we make request to store this in the .env file.
First we check if there "foo" environment variable in process.env.
If there is, the library return this value.
If there isn't, then the library checks the content of the .env file
If there is such value, the library returns it.
If there is no such value, the library return null
Variables of type foo,bar,baz will be considered as array-like. When such varialbes are read, the library will return the array ["foo","bar","baz"]
console.log(env.getEnv("PORT")) //=> "3000"
console.log(env.getEnv("baz")) //=> false
You can add variable, if such variable don't exist already
env.addEnv("foo","bar").then(console.log) //=> true as foo didn't exist before
env.addEnv("PORT","3001").then(console.log) //=> false as PORT already exist
Editing of variable is not directly possible. You need first to remove the variable, and then add the new value
env.delEnv("PORT").then(()=>{
env.addEnv("PORT","3001").then(console.log)
})
dotenvHelper.delEnv("PORT").then(console.log) //=> true(delete is performed)
dotenvHelper.delEnv("baz").then(console.log) //=> false(no delete as baz wasn't part of .env)
string | ArrayTakes a key and search for it in process.env
string | ArrayTakes a key and search for .env file It is actually a helper function used for deleting env variable, as process.env is not reliable then
string | ArrayTakes a key and search for it in process.env
PromiseTakes a key and try to remove it from in process.env
string | ArrayTakes a key and search for it in process.env
Kind: global function
Returns: string | Array - returns null if no match; string if match and array if match with "," inside
| Param | Type |
|---|---|
| key | string |
string | ArrayTakes a key and search for .env file It is actually a helper function used for deleting env variable, as process.env is not reliable then
Kind: global function
Returns: string | Array - returns null if no match; string if match and array if match with "," inside
| Param | Type |
|---|---|
| key | string |
string | ArrayTakes a key and search for it in process.env
Kind: global function
Returns: string | Array - returns null if no match; string if match and array if match with "," inside
| Param | Type |
|---|---|
| key | string |
| value | string |
PromiseTakes a key and try to remove it from in process.env
Kind: global function
Returns: Promise - Promise => boolean depends whether delete operation was perfomed or not
| Param | Type |
|---|---|
| key | string |
FAQs
Library for better use of environment variables
We found that dotenv-helper 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.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.