Reputation: 33
Is there a command to list all the npm_package_var
variables?
I know individually we can get the vars using npm_package_var syntax.
Is there a command that I can use to list all these vars?
Upvotes: 1
Views: 1454
Reputation: 24952
Short Answer: npm does not provide a built-in command that does exactly what you need. However, it can list all variables. For instance:
Firstly, cd
to your project directory.
Then run the following command to list all variables:
npm run env
The documentation states the following about the env
script:
The
env
script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an “env” command is defined in your package, it will take precedence over the built-in.
To list the npm_package_vars
only, consider piping the result of the aforementioned npm run env
command to either; grep
if using *nix, or to findstr
if using Windows.
For instance, firstly cd
to your project directory then run either of the following compound commands - depending on which OS you're using:
On *nix platforms run the following:
npm run env | grep ^npm_package_
Or, on Windows run the following instead:
npm run env | findstr /B npm_package_
Note (Git For Windows):
If you're using Git for Windows (i.e. if you're using git-bash as your preferred command line) then I recommend utilizing the aforementioned grep
command:
npm run env | grep ^npm_package_
However if for some reason you wanted to use findstr
instead of grep
, (when using git-bash), you'll need to replace the /B
option with -B
instead. For instance:
npm run env | findstr -B npm_package_
Or, if that fails, then try using two forward slashes instead. For instance:
npm run env | findstr //B npm_package_
Btw. The /B
option matches a pattern if it's at the beginning of a line. This is analogous to the caret ^
in GREP.`
Upvotes: 3