Product
Introducing Ruby Support in Socket
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
dotenv-cli
Advanced tools
A global executable to run applications with the ENV variables loaded by dotenv
The dotenv-cli package is a command-line interface tool that allows you to load environment variables from a .env file into your shell environment. This is particularly useful for managing environment variables in development and testing environments.
Load environment variables from a .env file
This feature allows you to load environment variables from a specified .env file and run a command with those variables. In this example, the environment variables from the .env file are loaded and then the Node.js application (app.js) is executed with those variables.
dotenv -e .env -- node app.js
Specify multiple .env files
This feature allows you to load environment variables from multiple .env files. The variables from the files are merged, with the latter files overriding the former ones if there are conflicts. In this example, variables from both .env and .env.local are loaded before running the Node.js application.
dotenv -e .env -e .env.local -- node app.js
Use different .env files for different environments
This feature allows you to specify different .env files for different environments, such as production, development, or testing. In this example, the environment variables from the .env.production file are loaded before running the Node.js application.
dotenv -e .env.production -- node app.js
The cross-env package allows you to set environment variables across different platforms in a consistent manner. Unlike dotenv-cli, which loads variables from a .env file, cross-env allows you to set them directly in the command line. This can be useful for setting variables in a cross-platform way, but it does not provide the same file-based management of environment variables.
The env-cmd package allows you to set environment variables from a file or inline. It is similar to dotenv-cli in that it can load variables from a file, but it also provides more flexibility in terms of specifying variables directly in the command line. Env-cmd also supports JSON and JavaScript configuration files, offering more versatility compared to dotenv-cli.
The dotenv package is a zero-dependency module that loads environment variables from a .env file into process.env. While it is similar to dotenv-cli in terms of loading variables from a .env file, it is designed to be used programmatically within your Node.js application rather than as a command-line tool.
$ npm install -g dotenv-cli
$ dotenv <command with arguments>
This will load the variables from the .env file in the current working directory and then run the command (using the new set of environment variables)
Another .env file could be specified using the -e flag:
$ dotenv -e .env2 <command with arguments>
If you want to check the value of an environment variable, use the -p
argument
$ dotenv -p NODE_ENV
FAQs
A global executable to run applications with the ENV variables loaded by dotenv
The npm package dotenv-cli receives a total of 848,162 weekly downloads. As such, dotenv-cli popularity was classified as popular.
We found that dotenv-cli demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket is launching Ruby support for all users. Enhance your Rails projects with AI-powered security scans for vulnerabilities and supply chain threats. Now in Beta!
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.