For Windows, my Node scripts should look like this:
"scripts": {
"start-docs": "SET NODE_ENV=development&&babel-node ./docs/Server.js"
}
But on Linux there's no SET
, so it would be like this:
"scripts": {
"start-docs": "NODE_ENV=development&&babel-node ./docs/Server.js"
}
Is there a way to declare environment variables in a way that is consistent and cross-platform?
To make permanent changes to the environment variables for all new accounts, go to your /etc/skel files, such as . bashrc , and change the ones that are already there or enter the new ones. When you create new users, these /etc/skel files will be copied to the new user's home directory.
I recently came across the cross-env project. It's pretty straight-forward
{
"scripts": {
"build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
}
}
That will set the build
environment variable to production
regardless of the OS.
I would vote against setting this in package.json because environment variables should be set dependent on your environment while package.json is most likely the same for every environment (you commit it to your version control system, right?). Instead you should use something like dotenv if you are looking for a clean and generic solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With