Use Environment Variables with npx

Oct 19, 2021 min read

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'