cross-env
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
cross-spawn | 7.0.3 | 7.3 kB | MIT | prod |
Cross-env is a popular npm package designed to allow you to use UNIX style environment variables on any platform, including Windows, without worrying about platform compatibility. It provides a command for setting environment variables across different platforms seamlessly. This makes it easier to run scripts that need to set and use environment variables across platforms like Windows, macOS, and Linux.
To use cross-env, it needs to be installed first as one of your project's development dependencies with the following command:
npm install --save-dev cross-env
Once installed, you can use the cross-env
command in your npm
or yarn
scripts. Here is an example:
{
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
}
}
In this example, the NODE_ENV
environment variable is set to production
by cross-env before executing the webpack
command. It's also possible to set multiple environment variables at once:
{
"scripts": {
"build": "cross-env FIRST_ENV=one SECOND_ENV=two node ./my-program"
}
}
Another helpful feature of cross-env is running commands with environment variables via cross-env-shell
. This is useful when you want the environment variable to be set across an entire inline shell script, rather than just one command.
{
"scripts": {
"greet": "cross-env-shell GREETING=Hi NAME=Joe \"echo $GREETING && echo $NAME\""
}
}
All documentation related to cross-env can be found on its Github page: https://github.com/kentcdodds/cross-env. Here, you can find more detailed usage instructions, examples, as well as information about differences between cross-env
and cross-env-shell
. Not to mention, details about its installation, other solutions and contributors can also be found in the repository.