Use Environment Variables with npx

If you use npx to execute commands and need to reference environment variables, the solution is very simple.

If you like to use npx to execute commands and would like to reference environment variables in your commands the solution is very simple. Adding the -c / --call flag to your npx command will execute the command as if it were an npm run command, giving access to all environment variables currently set.

Example:

npx -c '< command > $npm_package_version'