npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ilb/ldapenv-cli

v2.0.4

Published

A global executable to run applications with the ENV variables loaded by dotenv and ldapenv

Downloads

285

Readme

ldapenv-cli

Installing

NPM

$ npm install -g ldapenv-cli

Yarn

$ yarn global add ldapenv-cli

pnpm

pnpm add -g ldapenv-cli

Usage

$ 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).

Custom .env files

Another .env file could be specified using the -e flag:

$ dotenv -e .env2 <command with arguments>

Multiple .env files can be specified, and will be processed in order:

$ dotenv -e .env3 -e .env4 <command with arguments>

Cascading env variables

Some applications load from .env, .env.local, .env.development and .env.development.local (see #37 for more information). ldapenv-cli supports this using the -c flag for just .env and .env.local and -c development for the ones above.

Setting variable from command line

It is possible to set variable directly from command line using the -v flag:

$ dotenv -v VARIABLE=somevalue <command with arguments>

Multiple variables can be specified:

$ dotenv -v VARIABLE1=somevalue1 -v VARIABLE2=somevalue2 <command with arguments>

Variables set up from command line have higher priority than from env files.

Purpose of this is that standard approach VARIABLE=somevalue <command with arguments> doesn't work on Windows. The -v flag works on all the platforms.

Check env variable

If you want to check the value of an environment variable, use the -p flag

$ dotenv -p NODE_ENV

Flags to the underlying command

If you want to pass flags to the inner command use -- after all the flags to ldapenv-cli.

E.g. the following command without ldapenv-cli:

mvn exec:java -Dexec.args="-g -f"

will become the following command with ldapenv-cli:

$ dotenv -- mvn exec:java -Dexec.args="-g -f"

or in case the env file is at .my-env

$ dotenv -e .my-env -- mvn exec:java -Dexec.args="-g -f"

Variable expansion

We support expanding env variables inside .env files (See dotenv-expand npm package for more information)

For example:

IP=127.0.0.1
PORT=1234
APP_URL=http://${IP}:${PORT}

Using the above example .env file, process.env.APP_URL would be http://127.0.0.1:1234.

Variable expansion in the command

If your .env file looks like:

SAY_HI=hello!

you might expect dotenv echo "$SAY_HI" to display hello!. In fact, this is not what happens: your shell will first interpret your command before passing it to ldapenv-cli, so if SAY_HI envvar is set to "", the command will be expanded into dotenv echo: that's why ldapenv-cli cannot make the expansion you expect.

One possible way to get the desired result is:

$ dotenv -- bash -c 'echo "$SAY_HI"'

In bash, everything between ' is not interpreted but passed as is. Since $SAY_HI is inside '' brackets, it's passed as a string literal.

Therefore, ldapenv-cli will start a child process bash -c 'echo "$SAY_HI"' with the env variable SAY_HI set correctly which means bash will run echo "$SAY_HI" in the right environment which will print correctly hello

Debugging

You can add the --debug flag to output the .env files that would be processed and exit.

License

MIT