### Install via Wget Source: https://dotenvx.com/docs/armor/install.html Use wget to download and execute the installation script. ```bash wget -qO- https://dotenvx.sh | sh ``` -------------------------------- ### Install Express dependencies Source: https://dotenvx.com/docs/platforms/digital-ocean.html Install the necessary web server library for the Node.js example. ```bash npm install express --save ``` -------------------------------- ### Install Standalone Binary Source: https://dotenvx.com/docs/armor/install.html Download the binary directly and install it to your system path. ```bash # download it to `./dotenvx` curl -sfS --proto '=https' https://dotenvx.sh/$(uname)/$(uname -m).tgz | tar xz # install it to `/usr/local/bin/dotenvx` sudo install -m 755 dotenvx /usr/local/bin # check it works dotenvx help ``` ```bash # download version 0.6.9 curl -sfS --proto '=https' "https://dotenvx.sh/$(uname)/$(uname -m).tgz?version=v0.6.9" | tar xz # check the version ./dotenvx --version ``` -------------------------------- ### Start application Source: https://dotenvx.com/docs/process-managers/pm2.html Execute the start script to run the application with injected environment variables. ```bash npm start ``` -------------------------------- ### Install via Homebrew Source: https://dotenvx.com/docs/armor/install.html Use Homebrew to perform a global installation on macOS or Linux. ```bash # install with Homebrew and then use the dotenvx command brew tap dotenvx/brew brew trust dotenvx/brew brew install dotenvx ``` -------------------------------- ### Install dotenvx and wrangler Source: https://dotenvx.com/docs/platforms/cloudflare.html Install the necessary dependencies using bun. ```bash # Install dotenvx and wrangler bun install @dotenvx/dotenvx wrangler --save ``` -------------------------------- ### Run Frameworks with dotenvx Source: https://dotenvx.com/docs/quickstart/run.html Examples of running common framework commands with dotenvx. ```bash $ dotenvx run -- next dev $ dotenvx run -- npm start $ dotenvx run -- bin/rails s $ dotenvx run -- php artisan serve ``` -------------------------------- ### Install dependencies Source: https://dotenvx.com/docs/process-managers/pm2.html Install dotenvx and PM2 as project dependencies. ```bash npm install @dotenvx/dotenvx --save npm install pm2 --save ``` -------------------------------- ### Initialize Next.js Project Source: https://dotenvx.com/docs/package-managers/npm.html Create a new Next.js application using the hello-world example. ```bash npx create-next-app@latest --example hello-world . ``` -------------------------------- ### Examples of valid and invalid keys Source: https://dotenvx.com/docs/env-file.html Demonstration of naming conventions for environment variables. ```text DATABASE_URL # ok foobar # ok (but not recommended. use upcase) NO-WORK # <-- invalid !!! ÜBER # <-- invalid !!! 2MUCH # <-- invalid !!! ``` -------------------------------- ### Example .env.example output Source: https://dotenvx.com/docs/advanced/genexample.html The resulting file format generated by the command. ```text # .env.example HELLO="" ``` -------------------------------- ### Install Claude Code Source: https://dotenvx.com/docs/secrets-in-claude.html Install the Claude Code CLI tool using the provided installation script. ```bash $ curl -fsSL https://claude.ai/install.sh | bash $ claude --version ``` -------------------------------- ### Install Dotenvx SDK Source: https://dotenvx.com/docs/secrets-in-astro.html Install the Dotenvx package using npm, bun, or pnpm. ```bash $ npm install @dotenvx/dotenvx # or # bun add @dotenvx/dotenvx # pnpm add @dotenvx/dotenvx ``` -------------------------------- ### Install Dotenvx SDK and Next.js plugin Source: https://dotenvx.com/docs/frameworks/next.html Install the required packages using your preferred package manager. ```bash $ npm install @dotenvx/dotenvx $ npm install @dotenvx/next-env # or # bun add @dotenvx/dotenvx # bun add @dotenvx/next-env # pnpm add @dotenvx/dotenvx # pnpm add @dotenvx/next-env ``` -------------------------------- ### Setup Next.js environment files Source: https://dotenvx.com/docs/advanced/config-convention.html Create the standard set of environment files used by the Next.js convention. ```bash # Setup environment files $ echo "HELLO=development local" > .env.development.local $ echo "HELLO=local" > .env.local $ echo "HELLO=development" > .env.development $ echo "HELLO=env" > .env ``` -------------------------------- ### Install via Windows Winget Source: https://dotenvx.com/docs/armor/install.html Use the Windows Package Manager to install dotenvx. ```bash $ winget install dotenvx ``` -------------------------------- ### Configure package.json start script Source: https://dotenvx.com/docs/process-managers/pm2.html Update the start script to use dotenvx with pm2-runtime. ```json { "scripts": { "start": "dotenvx run -- pm2-runtime start ecosystem.config.js --env production" }, "dependencies": { "@dotenvx/dotenvx": "^1.48.4", "pm2": "^5.3.0" } } ``` -------------------------------- ### Configure production start script Source: https://dotenvx.com/docs/process-managers/pm2.html Update the start script to load a specific environment file. ```json { "scripts": { "start": "dotenvx run -f .env.production -- pm2-runtime start ecosystem.config.js --env production" }, ... } ``` -------------------------------- ### Install dotenvx Source: https://dotenvx.com/docs/background-jobs/triggerdotdev.html Command to install the dotenvx package as a dependency. ```bash $ npm install @dotenvx/dotenvx --save ``` -------------------------------- ### Install pre-commit hook Source: https://dotenvx.com/docs/advanced/precommit-install.html Executes the installation of the pre-commit hook to the local git repository. ```bash $ dotenvx precommit --install ▣ dotenvx precommit installed [.git/hooks/pre-commit] ``` -------------------------------- ### Install Cursor CLI Source: https://dotenvx.com/docs/secrets-in-cursor.html Installs the Cursor command-line interface using a shell script. ```bash $ curl https://cursor.com/install -fsS | bash ``` -------------------------------- ### Troubleshoot installation issues Source: https://dotenvx.com/docs/frameworks/next.html Clear local dependencies and reinstall if overrides are not taking effect. ```bash rm -rf node_modules package-lock.json npm install ``` -------------------------------- ### Install via cURL Source: https://dotenvx.com/docs/armor/install.html Use the shell script to install dotenvx on Unix-like systems. ```bash $ curl -sfS https://dotenvx.sh | sh ◈ installed (dotenvx) ``` -------------------------------- ### Setup Flow environment files Source: https://dotenvx.com/docs/advanced/config-convention.html Create the standard set of environment files used by the dotenv-flow convention. ```bash # Setup environment files $ echo "HELLO=development local" > .env.development.local $ echo "HELLO=development" > .env.development $ echo "HELLO=local" > .env.local $ echo "HELLO=env" > .env ``` -------------------------------- ### Deploy to Netlify Source: https://dotenvx.com/docs/platforms/netlify.html Commands to install dependencies and deploy the application to Netlify. ```bash brew install vips # most machines can skip this step npx netlify-cli@latest deploy --build --prod ``` -------------------------------- ### Install and use via NPM Source: https://dotenvx.com/docs/armor/install.html Install the package as a dependency and configure it in your Node.js application. ```bash $ npm install @dotenvx/dotenvx ``` ```javascript // index.js require('@dotenvx/dotenvx').config() // or import '@dotenvx/dotenvx/config' if you're using esm console.log(`Hello ${process.env.HELLO}`) ``` -------------------------------- ### Execution output Source: https://dotenvx.com/docs/sdk/get-mask.html Example output when running the script. ```bash $ node index.js abcdef****** ``` -------------------------------- ### Install NPM Global Source: https://dotenvx.com/docs/armor/install.html Install dotenvx globally using the npm package manager. ```bash npm install @dotenvx/dotenvx --global dotenvx help ``` -------------------------------- ### Heroku Deployment Logs Source: https://dotenvx.com/docs/platforms/heroku.html Example output showing successful environment injection. ```text heroku[web.1]: Starting process with command `dotenvx run -- node index.js` app[web.1]: ⟐ injected env (2) from .env.production app[web.1]: Server running on port:7521/ ``` -------------------------------- ### Generate .env.example from multiple files Source: https://dotenvx.com/docs/advanced/genexample-f.html Use the -f flag multiple times to specify each source .env file to include in the generated example file. ```bash $ echo "HELLO=World" > .env echo "DB_HOST=example.com" > .env.production dotenvx genexample -f .env -f .env.production ``` -------------------------------- ### Monorepo directory structure Source: https://dotenvx.com/docs/monorepos.html Example layout showing a root .env file and a workspace-specific application. ```text my-monorepo/ .env .env.keys apps/ web/ index.js ``` -------------------------------- ### Run Express Server Source: https://dotenvx.com/docs/package-managers/npm.html Start the Express server using the configured npm script. ```bash $ npm start > start > dotenvx run -- node index.js ⟐ injected env (1) from .env Server running on port:3000 ``` -------------------------------- ### Define environment variables in .env Source: https://dotenvx.com/docs/advanced/config-env-keys-file.html Example of a standard .env file content. ```text # .env HELLO="World" ``` -------------------------------- ### Build output verification Source: https://dotenvx.com/docs/platforms/netlify.html Example output showing successful environment injection during build. ```bash $ npm run build > build > dotenvx run -- next build ⟐ injected env (2) from .env.production ✓ Compiled successfully ``` -------------------------------- ### Successful injection output Source: https://dotenvx.com/docs/platforms/digital-ocean.html Example console output confirming successful environment injection. ```text ⟐ injected env (2) from .env.production Server running on port:3000 ``` -------------------------------- ### Configuring the Dockerfile Source: https://dotenvx.com/docs/platforms/docker.html Install dotenvx and set it as the entrypoint to automatically decrypt and inject secrets at runtime. ```dockerfile FROM node:22-alpine RUN apk add --no-cache curl \ && curl -sfS https://dotenvx.sh | sh \ && apk del curl WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . ENTRYPOINT ["dotenvx", "run", "--"] CMD ["node", "index.js"] ``` -------------------------------- ### Define PM2 ecosystem configuration Source: https://dotenvx.com/docs/process-managers/pm2.html Example configuration for an ecosystem.config.js file. ```javascript module.exports = { apps : [{ script: 'index.js', watch: '.' }] }; ``` -------------------------------- ### Express Application Server Source: https://dotenvx.com/docs/package-managers/npm.html A basic Express server setup using environment variables. ```javascript // index.js const express = require('express') const app = express() const PORT = process.env.PORT || 3000 app.get('/', (req, res) => { res.send(`Hello ${process.env.HELLO || ''}`) }) app.listen(PORT, () => { console.log(`Server running on port:${PORT}`) }) ``` -------------------------------- ### Example .env.keys file content Source: https://dotenvx.com/docs/env-keys-file-deprecated.html This file stores decryption keys for different environments. Do not commit this file to source control. ```text #/!!!!!!!!!!!!!!!!!!!.env.keys!!!!!!!!!!!!!!!!!!!!!!/ #/ DOTENV_KEYs. DO NOT commit to source control / #/ [how it works](https://dotenv.org/env-keys) / #/--------------------------------------------------/ DOTENV_KEY_DEVELOPMENT="dotenv://:key_e507c60efa8841d8d5bbb85bd701ee92406cf3b06506d1d80f1553c2a72791e4@dotenvx.com/vault/.env.vault?environment=development" DOTENV_KEY_PRODUCTION="dotenv://:key_10283719af6a30ef49050048617f4fea10c23a38021fbebeb9fd858caa01852e@dotenvx.com/vault/.env.vault?environment=production" ``` -------------------------------- ### Express package.json Configuration Source: https://dotenvx.com/docs/package-managers/npm.html Define the start script to use dotenvx for an Express application. ```json { "dependencies": { "@dotenvx/dotenvx": "^1.48.4", "express": "^4.18.2" }, "scripts": { "start": "dotenvx run -- node index.js" } } ``` -------------------------------- ### Example directory structure for nextjs convention Source: https://dotenvx.com/docs/advanced/config-path-directory-convention.html Shows the files resolved when using the nextjs convention within the apps/web directory. ```text apps/web/.env.development.local apps/web/.env.local apps/web/.env.development apps/web/.env ``` -------------------------------- ### Configure Dockerfile for prebuild Source: https://dotenvx.com/docs/advanced/prebuild-directory.html Install dotenvx and execute the prebuild command for a specific directory within a Dockerfile. ```dockerfile # Dockerfile RUN curl -fsS https://dotenvx.sh | sh ... RUN dotenvx prebuild apps/backend CMD ["dotenvx", "run", "--", "node", "apps/backend/index.js"] ``` -------------------------------- ### Define .env file content Source: https://dotenvx.com/docs/env-file.html Basic example of key-value pairs stored in a .env file. ```text # .env STRIPE_API_KEY=scr_12345 TWILIO_API_KEY=abcd1234 ``` -------------------------------- ### Install Dotenvx SDK Source: https://dotenvx.com/docs/secrets-in-bun.html Add the Dotenvx package to your Bun project using the bun add command. ```bash $ bun add @dotenvx/dotenvx ``` -------------------------------- ### Initialize a uv project Source: https://dotenvx.com/docs/secrets-in-uv.html Create a new project directory and initialize it with uv. ```bash uv init hello-world cd hello-world ``` -------------------------------- ### Initialize Remix Project Source: https://dotenvx.com/docs/package-managers/npm.html Create a new Remix application. ```bash npx create-remix@latest ``` -------------------------------- ### Example .env.vault file structure Source: https://dotenvx.com/docs/env-vault-file.html Displays the structure of an encrypted .env.vault file containing development and production environment keys. ```text #/-------------------.env.vault---------------------/ #/ cloud-agnostic vaulting standard / #/ [how it works](https://dotenvx.com/env-vault) / #/--------------------------------------------------/ # development DOTENV_VAULT_DEVELOPMENT="V4NYVn0Pow6Uf2ez2mbHEzTrYURloHL6VDAFRLqnQBppA/OmHI5x5AXoxCMVor7wOg==" # production DOTENV_VAULT_PRODUCTION="YZkhtbh1IlzBgIamAAsG5nzGPfH6p8Zbuj9egXoziviVu/eYIyNjJWtIYyhiW/vHhFbqbsvo5+P9b27OC6ZC7qU=" ``` -------------------------------- ### Run via NPX Source: https://dotenvx.com/docs/armor/install.html Execute dotenvx without a permanent installation using npx. ```bash npx @dotenvx/dotenvx help ``` -------------------------------- ### Running in production Source: https://dotenvx.com/docs/platforms/docker-compose.html Inject the private key from the deployment system's secret store when starting Docker Compose. ```bash DOTENV_PRIVATE_KEY="$DOTENV_PRIVATE_KEY" docker compose up --build ``` -------------------------------- ### Install dotenvx via npm Source: https://dotenvx.com/docs/package-managers/npm.html Install the dotenvx package as a dependency. ```bash npm install @dotenvx/dotenvx --save ``` ```bash npm install express @dotenvx/dotenvx --save ``` -------------------------------- ### Access environment variables in Java Source: https://dotenvx.com/docs/secrets-in-java.html Example Java code demonstrating how to retrieve an environment variable using System.getenv(). ```java public class Index { public static void main(String[] args) { String hello = System.getenv("HELLO"); System.out.println("Hello " + hello); } } ``` -------------------------------- ### Install NPM Local CLI Source: https://dotenvx.com/docs/armor/install.html Use dotenvx as a local CLI tool within a Node.js project. ```bash npm i @dotenvx/dotenvx --save ``` ```json { "scripts": { "start": "./node_modules/.bin/dotenvx run -- node index.js" }, "dependencies": { "@dotenvx/dotenvx": "^1.48.4" } } ``` -------------------------------- ### Verify Cursor CLI Installation Source: https://dotenvx.com/docs/secrets-in-cursor.html Checks the installed version of the Cursor agent. ```bash $ agent --version ``` -------------------------------- ### Pretty print environment variables Source: https://dotenvx.com/docs/cli/get-pretty-print.html Formats the output of the get command into a readable JSON structure. ```bash $ echo "HELLO=World" > .env dotenvx get --pretty-print { "HELLO": "World" } ``` -------------------------------- ### Building and Running the Container Source: https://dotenvx.com/docs/platforms/docker.html Build the image and run it by passing the private key via the environment file. ```bash docker build -t myapp . docker run --env-file .env.keys myapp ``` -------------------------------- ### Generate .env.example in a directory Source: https://dotenvx.com/docs/advanced/genexample-directory.html Creates a .env.example file in the specified path based on existing .env files. ```bash $ echo "HELLO=World" > .env mkdir -p apps/backend echo "HELLO=Backend" > apps/backend/.env dotenvx genexample apps/backend ▣ generated (.env.example) ``` -------------------------------- ### Locked private key format Source: https://dotenvx.com/docs/advanced/lock-up.html Example of how a private key appears in the .env.keys file after being locked. ```text # .env.keys DOTENV_PRIVATE_KEY=locked:02f5b97ad58b49ae324cd4e7937bc19b251d006b31cacf46f789eeaf03f923cedc:AZIPDxKqjPLiGl5b4CqVGbR3CIBDUcqHthGaoeWLoUvxbTHJkj3jGoGWGaxFSDUJGQUmWDaExRzxKpVydYF_7qiWr1ecqksOFho5t3EMwKbqX2-y-LZO9K3a4SJaYAjDJXpn3NwG4vAt1oLmGA ``` -------------------------------- ### Define Bitwarden reference in .env Source: https://dotenvx.com/docs/sdk/config-no-bitwarden.html Example of a .env file containing a Bitwarden reference that would normally be resolved. ```text # .env API_KEY="bw://My GitHub Account/password" ``` -------------------------------- ### Check dotenvx version Source: https://dotenvx.com/docs/cli/version.html Use the --version flag to display the currently installed version of the dotenvx CLI. ```bash $ dotenvx --version X.X.X ``` ```bash $ dotenvx -V X.X.X ``` -------------------------------- ### Create application entry point Source: https://dotenvx.com/docs/process-managers/pm2.html A basic HTTP server that reads environment variables. ```javascript // index.js const PORT = process.env.PORT || 3000 const http = require('http') const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end(`Hello ${process.env.HELLO}`) }); server.listen(PORT, () => { console.log(`Server running on port:${PORT}/`); }); ``` -------------------------------- ### Initialize Astro Project Source: https://dotenvx.com/docs/package-managers/npm.html Create a new Astro application using the latest version. ```bash npm create astro@latest ``` -------------------------------- ### dotenvx get --all Source: https://dotenvx.com/docs/advanced/get-all.html Retrieves all environment variables available to the current process, including system environment variables and those loaded from .env files. ```APIDOC ## CLI Command: dotenvx get --all ### Description Returns all environment variables, including preset machine environment variables and variables defined in local .env files. ### Usage `dotenvx get --all` ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get --all {"PWD":"/some/file/path","USER":"username","LIBRARY_PATH":"/usr/local/lib", ..., "HELLO":"World"} ``` ``` -------------------------------- ### Encrypt and retrieve keypair with custom .env.keys path Source: https://dotenvx.com/docs/advanced/keypair-fk.html Demonstrates creating a directory, setting an environment variable, encrypting it using a specific key file, and retrieving the resulting keypair. ```bash $ mkdir -p apps/app1 echo "HELLO=World" > apps/app1/.env dotenvx encrypt -fk .env.keys -f apps/app1/.env dotenvx keypair -fk .env.keys -f apps/app1/.env {"DOTENV_PUBLIC_KEY":"","DOTENV_PRIVATE_KEY":""} ``` -------------------------------- ### Generate and display keypair for an encrypted .env file Source: https://dotenvx.com/docs/advanced/keypair-f.html Creates a sample .env file, encrypts it, and then retrieves the associated public and private keys. ```bash $ echo "HELLO=Production" > .env.production dotenvx encrypt -f .env.production dotenvx keypair -f .env.production {"DOTENV_PUBLIC_KEY_PRODUCTION":"","DOTENV_PRIVATE_KEY_PRODUCTION":""} ``` -------------------------------- ### Launch and deploy to Fly Source: https://dotenvx.com/docs/platforms/fly.html Commands to initialize and deploy the application to Fly.io. ```bash flyctl launch flyctl deploy ``` -------------------------------- ### View generated .env.example content Source: https://dotenvx.com/docs/advanced/genexample-directory.html Displays the contents of the generated .env.example file. ```text # apps/backend/.env.example HELLO="" ``` -------------------------------- ### Install Codex CLI Source: https://dotenvx.com/docs/secrets-in-codex.html Install the Codex CLI globally using npm to access the codex command. ```bash $ npm install -g @openai/codex $ codex --version ``` -------------------------------- ### Display global help Source: https://dotenvx.com/docs/cli/help.html Lists all available commands and global options for the dotenvx CLI. ```bash $ dotenvx help Usage: dotenvx run -- yourcommand a secure dotenv–from the creator of `dotenv` Options: -V, --version output the version number -h, --help display help for command Commands: run get [KEY] set encrypt decrypt keypair [KEY] ls [directory] gitignore genexample [directory] validate precommit [directory] prebuild [directory] ``` -------------------------------- ### Installing dotenvx in Dockerfile Source: https://dotenvx.com/docs/platforms/docker-compose.html Add the dotenvx installation steps to your Dockerfile to enable secret injection at runtime. ```dockerfile FROM node:22-alpine RUN apk add --no-cache curl \ && curl -sfS https://dotenvx.sh | sh \ && apk del curl WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . CMD ["node", "index.js"] ``` -------------------------------- ### Install Dotenvx Armor via cURL Source: https://dotenvx.com/docs/advanced/armor.html Use this command to install the Dotenvx CLI on Unix-based systems. ```bash curl -sfS https://dotenvx.sh/install.sh | sh ``` -------------------------------- ### Initialize and deploy to Railway Source: https://dotenvx.com/docs/platforms/railway.html Commands to initialize the project, upload to Railway, and configure the domain. ```bash npx @railway/cli@latest init npx @railway/cli@latest up npx @railway/cli@latest domain ``` -------------------------------- ### Get key with strict error handling Source: https://dotenvx.com/docs/advanced/get-key-strict.html Executes a get request that returns an error message and non-zero exit code if the key is not found. ```bash $ dotenvx get DOES_NOT_EXIST --strict [MISSING_KEY] missing key (DOES_NOT_EXIST) ``` -------------------------------- ### Define required variables in .env.example Source: https://dotenvx.com/docs/advanced/validate.html Create an .env.example file to declare the environment variables your application requires. ```text # .env.example DATABASE_URL= API_KEY= SENTRY_DSN= # optional ``` -------------------------------- ### Run with DOTENV_ENV and dotenv-flow convention Source: https://dotenvx.com/docs/advanced/run-convention-flow-dotenv-env.html Demonstrates setting up environment files and executing a script using the dotenv-flow convention via the CLI. ```bash $ echo "HELLO=production local" > .env.production.local echo "HELLO=production" > .env.production echo "HELLO=local" > .env.local echo "HELLO=env" > .env echo "console.log('Hello ' + process.env.HELLO)" > index.js DOTENV_ENV=production dotenvx run --convention=flow -- node index.js ⟐ injected env (1) from .env.production.local, .env.production, .env.local, .env Hello production local ``` -------------------------------- ### get Source: https://dotenvx.com/docs/sdk/introduction.html Retrieves an environment variable value. ```APIDOC ## get ### Description Retrieves the value of a specific environment variable. ``` -------------------------------- ### Add dotenvx Buildpack Source: https://dotenvx.com/docs/platforms/heroku.html Install the dotenvx buildpack to the Heroku application. ```bash heroku buildpacks:add https://github.com/dotenvx/heroku-buildpack-dotenvx ``` -------------------------------- ### Run with dotenv-flow convention Source: https://dotenvx.com/docs/advanced/run-convention-flow.html Demonstrates setting up environment files and executing a command using the --convention=flow flag. ```bash $ echo "HELLO=development local" > .env.development.local echo "HELLO=development" > .env.development echo "HELLO=local" > .env.local echo "HELLO=env" > .env echo "console.log('Hello ' + process.env.HELLO)" > index.js NODE_ENV=development dotenvx run --convention=flow -- node index.js ⟐ injected env (1) from .env.development.local, .env.development, .env.local, .env Hello development local ``` -------------------------------- ### Run native up with specific files Source: https://dotenvx.com/docs/cli/native/up.html Uses the -f and -fk flags to specify custom paths for the environment file and the keys file. ```bash $ dotenvx native up -f .env.production -fk .env.keys ``` -------------------------------- ### dotenvx --version Source: https://dotenvx.com/docs/cli/version.html Retrieves the installed version of the dotenvx CLI. ```APIDOC ## CLI Command: dotenvx --version ### Description Prints the currently installed version of the dotenvx CLI. ### Usage `dotenvx --version` or `dotenvx -V` ### Output Returns the version string (e.g., X.X.X). ``` -------------------------------- ### dotenvx get KEY Source: https://dotenvx.com/docs/advanced/get-key.html Retrieves the value of a specific environment variable. ```APIDOC ## dotenvx get KEY ### Description Returns the value of a single environment variable specified by the KEY. ### Usage `dotenvx get [KEY]` ### Parameters - **KEY** (string) - Required - The name of the environment variable to retrieve. ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get HELLO World ``` ``` -------------------------------- ### Run Any Command with dotenvx Source: https://dotenvx.com/docs/quickstart/run.html General syntax for running any application boot command with dotenvx. ```bash # dotenvx works with any language or framework # 1. create your application # 2. create your .env file # 3. preface its boot command with `dotenvx run --` $ dotenvx run -- your-app-boot-command ``` -------------------------------- ### Running Compose locally Source: https://dotenvx.com/docs/platforms/docker-compose.html Use the .env.keys file to provide the private key during local development. ```bash docker compose --env-file .env.keys up --build ``` -------------------------------- ### Generate .env.example from .env Source: https://dotenvx.com/docs/advanced/genexample.html Creates a template file with empty values based on the current .env file contents. ```bash $ echo "HELLO=World" > .env dotenvx genexample ▣ generated (.env.example) ``` -------------------------------- ### Run with Next.js convention via CLI flag Source: https://dotenvx.com/docs/advanced/run-convention-nextjs.html Demonstrates setting up environment files and executing a script using the --convention=nextjs flag. ```bash $ echo "HELLO=development local" > .env.development.local echo "HELLO=local" > .env.local echo "HELLO=development" > .env.development echo "HELLO=env" > .env echo "console.log('Hello ' + process.env.HELLO)" > index.js dotenvx run --convention=nextjs -- node index.js ⟐ injected env (1) from .env.development.local, .env.local, .env.development, .env Hello development local ``` -------------------------------- ### Astro Page Component Source: https://dotenvx.com/docs/package-managers/npm.html Example of accessing environment variables in an Astro page. ```astro --- --- Astro

Hello {import.meta.env.HELLO}

``` -------------------------------- ### Update Dockerfile for dotenvx Source: https://dotenvx.com/docs/platforms/digital-ocean.html Install dotenvx and modify the CMD to use it for running the application. ```dockerfile # Dockerfile FROM node:20 WORKDIR /app # Install dotenvx RUN curl -sfS https://dotenvx.sh/install.sh | sh COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 # Prepend dotenvx run CMD ["dotenvx", "run", "--", "node", "index.js"] ``` -------------------------------- ### Decrypting .env files with -fk Source: https://dotenvx.com/docs/advanced/decrypt-fk.html Demonstrates creating an environment file, encrypting it using a specific key file, and decrypting it back using the same key file path. ```bash $ mkdir -p apps/app1 echo "HELLO=World" > apps/app1/.env dotenvx encrypt -fk .env.keys -f apps/app1/.env ◈ encrypted (apps/app1/.env) dotenvx decrypt -fk .env.keys -f apps/app1/.env ◇ decrypted (apps/app1/.env) ``` -------------------------------- ### dotenvx get -ik Source: https://dotenvx.com/docs/cli/get-include-key.html Retrieves environment variables that match a specified glob pattern. ```APIDOC ## CLI Command: dotenvx get -ik ### Description Retrieves environment variables from the .env file, filtering the output to include only keys that match the provided glob pattern. ### Usage `dotenvx get -ik ` ### Parameters - **glob-pattern** (string) - Required - The pattern used to match environment variable keys (e.g., "H*"). ### Example ```bash $ echo "HELLO=World\nHOLA=Mundo\nGOODBYE=World" > .env $ dotenvx get -ik "H*" {"HELLO":"World","HOLA":"Mundo"} ``` ``` -------------------------------- ### Next.js Page Router implementation Source: https://dotenvx.com/docs/platforms/vercel.html Example using getServerSideProps to fetch variables with dotenvx. ```typescript import * as dotenvx from '@dotenvx/dotenvx'; export default function Page({ hello }: { hello: string }) { return

Hello {hello}

; } export async function getServerSideProps() { const hello = await dotenvx.get('HELLO') return { props: { hello, }, }; } ``` -------------------------------- ### Define environment variable values Source: https://dotenvx.com/docs/env-file.html Examples of simple, interpolated, non-interpolated, and multiline values. ```text SIMPLE=xyz123 INTERPOLATED="Multiple\nLines" NON_INTERPOLATED='raw text without variable interpolation' MULTILINE = `long text here, e.g. a private SSH key` ``` -------------------------------- ### Build and run Docker container Source: https://dotenvx.com/docs/platforms/digital-ocean.html Build the image and run the container locally. ```bash docker build -t app . && docker run -it --init --rm -p 3000:3000 app ``` -------------------------------- ### Get environment variable with masking Source: https://dotenvx.com/docs/sdk/get.html Demonstrates the syntax for applying a mask to the retrieved environment variable. ```javascript get(KEY, {mask: true}) ``` -------------------------------- ### dotenvx get --pretty-print Source: https://dotenvx.com/docs/cli/get-pretty-print.html Retrieves environment variables and outputs them in a formatted JSON structure. ```APIDOC ## CLI Command: dotenvx get --pretty-print ### Description This command retrieves the environment variables from the current configuration and outputs them as a pretty-printed JSON object. ### Usage `dotenvx get --pretty-print` ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get --pretty-print { "HELLO": "World" } ``` ``` -------------------------------- ### Handling missing .env files Source: https://dotenvx.com/docs/advanced/run-contextual-help.html Demonstrates the error output and suggested fix when a specified environment file does not exist. ```bash $ dotenvx run -f .env.missing -- sh -c 'echo $HELLO' [MISSING_ENV_FILE] missing file (/Users/scottmotte/Code/dotenvx/playground/apr-16/.env.missing). fix: [echo "HELLO=World" > .env.missing] ``` -------------------------------- ### dotenvx get Source: https://dotenvx.com/docs/cli/get-json.html Retrieves all key/value pairs from the local .env file and returns them as a JSON object. ```APIDOC ## dotenvx get ### Description Returns a JSON response containing all key/value pairs defined in the current .env file. ### Usage `dotenvx get` ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get {"HELLO":"World"} ``` ``` -------------------------------- ### dotenvx get --format colon Source: https://dotenvx.com/docs/cli/get-colon.html Retrieves environment variables and displays them in a colon-separated format. ```APIDOC ## dotenvx get --format colon ### Description Returns the environment variables from the current configuration in a colon-separated format (KEY: Value). ### Usage `dotenvx get --format colon` ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get --format colon HELLO: World ``` ``` -------------------------------- ### Execute the application Source: https://dotenvx.com/docs/advanced/config-overload.html Run the script to observe the injected environment variables. ```bash $ node index.js ⟐ injected env (1) from .env.local, .env Hello World ``` -------------------------------- ### Create production environment file Source: https://dotenvx.com/docs/armor/production.html Define production-specific environment variables in a .env.production file. ```text # .env.production HELLO="production" ``` -------------------------------- ### Retrieve environment variable from specific file Source: https://dotenvx.com/docs/advanced/get-key-f.html Demonstrates setting up two .env files and retrieving a specific key's value from the production file. ```bash $ echo "HELLO=World" > .env echo "HELLO=production" > .env.production dotenvx get HELLO -f .env.production production ``` -------------------------------- ### dotenvx get KEY --ignore Source: https://dotenvx.com/docs/cli/get-key-ignore.html Retrieve an environment variable while ignoring specific error codes. ```APIDOC ## dotenvx get KEY --ignore ### Description Retrieves the value of a specified environment variable key while suppressing specific error codes that may occur during the process. ### Usage `dotenvx get [KEY] --ignore=[ERROR_CODES]` ### Parameters - **KEY** (string) - Required - The environment variable key to retrieve. - **--ignore** (string) - Optional - A space-separated list of error codes to ignore (e.g., MISSING_ENV_FILE, MISSING_KEY). ### Environment Variable - **DOTENV_CONFIG_IGNORE** (string) - Optional - A comma-separated list of error codes to ignore globally for the command execution. ``` -------------------------------- ### dotenvx get -ek Source: https://dotenvx.com/docs/cli/get-exclude-key.html Retrieves environment variables while excluding keys that match a specified glob pattern. ```APIDOC ## CLI Command: dotenvx get -ek ### Description Retrieves environment variables from the configuration, allowing the user to exclude specific keys that match a provided glob pattern. ### Usage `dotenvx get [options] -ek ` ### Options - **--exclude-key, -ek** (string) - Required - A glob pattern used to identify and exclude keys from the output. ``` -------------------------------- ### dotenvx get --all --pretty-print Source: https://dotenvx.com/docs/cli/get-all-pretty-print.html Retrieves all environment variables and outputs them as a pretty-printed JSON object. ```APIDOC ## CLI Command: dotenvx get --all --pretty-print ### Description This command retrieves all environment variables available in the current context and outputs them in a formatted, human-readable JSON structure. ### Usage `dotenvx get --all --pretty-print` ### Options - **--all**: Fetches all environment variables. - **--pretty-print**: Formats the output as readable JSON. ### Example ```bash $ echo "HELLO=World" > .env $ dotenvx get --all --pretty-print { "PWD": "/some/filepath", "USER": "username", "LIBRARY_PATH": "/usr/local/lib", ..., "HELLO": "World" } ``` ``` -------------------------------- ### dotenvx get KEY -f Source: https://dotenvx.com/docs/advanced/get-key-f.html Retrieves the value of a specified environment variable from a target .env file. ```APIDOC ## CLI Command: dotenvx get KEY -f ### Description Returns a single environment variable's value from a specific .env file. ### Usage `dotenvx get [KEY] -f [FILE_PATH]` ### Parameters - **KEY** (string) - Required - The name of the environment variable to retrieve. - **-f** (string) - Required - The path to the specific .env file to read from. ### Example ```bash $ echo "HELLO=World" > .env echo "HELLO=production" > .env.production dotenvx get HELLO -f .env.production # Output: production ``` ``` -------------------------------- ### Use dotenvx get with export Source: https://dotenvx.com/docs/advanced/get-shell.html Exports environment variables into the current shell session before running a command. ```bash $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js export $(dotenvx get --format=shell) node index.js Hello value World ``` -------------------------------- ### Initialize PM2 configuration Source: https://dotenvx.com/docs/process-managers/pm2.html Generates an ecosystem.config.js file for PM2 process management. ```bash pm2 init ``` -------------------------------- ### Inject Secrets in Express Source: https://dotenvx.com/docs/secrets-in-express.html Example of initializing Dotenvx and accessing environment variables within an Express application. ```javascript require('@dotenvx/dotenvx').config() const express = require('express') const app = express() app.use(express.json()) app.get('/', (req, res) => { res.json({ HELLO: process.env.HELLO }) }) const port = process.env.PORT || 3000 app.listen(port, () => { console.log(`Server running on http://localhost:${port}`) }) ``` -------------------------------- ### Define 1Password reference in .env Source: https://dotenvx.com/docs/sdk/config-no-1password.html Example of an environment variable using the op:// URI scheme. ```dotenv # .env API_KEY=op://Personal/my_api_key/password ``` -------------------------------- ### Run command with redaction Source: https://dotenvx.com/docs/cli/run-redact.html Demonstrates setting up environment variables and executing a node script with redaction enabled. ```bash $ echo "SECRET=super-secret-value" > .env $ echo "VISIBLE_PLAIN=visible-value" >> .env $ echo "console.log(process.env.SECRET, process.env.VISIBLE_PLAIN)" > index.js $ dotenvx run --redact --quiet -- node index.js [REDACTED] visible-value ``` -------------------------------- ### Define environment variables for masking Source: https://dotenvx.com/docs/sdk/config-mask.html Example .env file content containing a secret value to be masked. ```text # .env SECRET="abcdefghijkl" ``` -------------------------------- ### Compose multiple .env files with dotenvx run Source: https://dotenvx.com/docs/advanced/run-f.html Demonstrates creating two .env files and running a Node.js script that consumes variables from both, with the first file taking precedence. ```bash $ echo "HELLO=local" > .env.local echo "HELLO=World" > .env echo "console.log('Hello ' + process.env.HELLO)" > index.js dotenvx run -f .env.local -f .env -- node index.js ⟐ injected env (1) from .env.local, .env Hello local ``` -------------------------------- ### Define multiline environment variable Source: https://dotenvx.com/docs/advanced/run-multiline.html Example of a multiline PEM key defined within a .env file. ```text # .env MULTILINE_PEM="-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/ bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/ kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V u4QuUoobAgMBAAE= -----END PUBLIC KEY-----" ``` -------------------------------- ### Display command-specific help Source: https://dotenvx.com/docs/cli/help.html Provides detailed usage information for a specific dotenvx command. ```bash $ dotenvx help run Usage: dotenvx run [options] -- yourcommand ``` -------------------------------- ### Configure dotenvx with directory and convention Source: https://dotenvx.com/docs/advanced/config-path-directory-convention.html Loads environment files from a specified directory using the nextjs convention. ```javascript // index.js require('@dotenvx/dotenvx').config({ path: 'apps/web', convention: 'nextjs' }) ``` -------------------------------- ### Configure encrypted .env files Source: https://dotenvx.com/docs/env-file.html Include a public key and use the encrypted: prefix for sensitive values. ```text #/-------------------[DOTENV_PUBLIC_KEY]--------------------/ #/ public-key encryption for .env files / #/ [how it works](https://dotenvx.com/encryption) / #/----------------------------------------------------------/ DOTENV_PUBLIC_KEY="03f98bf6e00bce6fdb933bc47738d671dffb75a916fa8c89854bdfa3483902632f" # .env HELLO="encrypted:BCV9qZmblsUm77IxgrEqY9t67qDVWQZg6jpogQhBWa9SaOCtvheEQ5/eUfPCigQ7KB6vN//6vFE+2+orG7LmUorWhe1JapWct6Dz58IY6mXi+ONs51F7TSed6R/T9e+lDBWYH04p" ``` -------------------------------- ### dotenvx get KEY -fk Source: https://dotenvx.com/docs/cli/get-key-fk.html Retrieves a value for a specified key using a custom path for the .env.keys file. ```APIDOC ## dotenvx get KEY -fk ### Description Retrieves the value of a specified key. The -fk flag allows the user to specify a .env.keys file or a directory containing one to be used for decryption. ### Usage `dotenvx get [KEY] -f [FILE_PATH] -fk [KEY_FILE_PATH]` ### Parameters - **KEY** (string) - Required - The environment variable key to retrieve. - **-f** (string) - Optional - Path to the .env file. - **-fk** (string) - Required - Path to the .env.keys file or directory containing it. ### Example ```bash dotenvx get HELLO -f . -fk ../.. ``` ``` -------------------------------- ### Configure netlify.toml Source: https://dotenvx.com/docs/platforms/netlify.html Configuration file for Netlify to handle Next.js builds. ```toml [[plugins]] package = "@netlify/plugin-nextjs" [build] command = "npm run build" publish = ".next" ``` -------------------------------- ### Use dotenvx get with env Source: https://dotenvx.com/docs/advanced/get-shell.html Injects environment variables directly into a command execution using the env utility. ```bash $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js env $(dotenvx get --format=shell) node index.js Hello value World ```