Because we don't want sensitive data in the project code, including the package.json file, using environment variables would be a logical choice in my opinion.
Example package.json:
"dependencies": { "accounting": "~0.4.0", "async": "~1.4.2", "my-private-module":"git+https://${BB_USER}:${BB_PASS}@bitbucket.org/foo/bar.git"
Is this possible?
The question is not if this is wise or not good, just if it's possible.
You can use environment values to inject in your package. json like this: Any environment variables that start with npm_config_ will be interpreted as a configuration parameter. For example, putting npm_config_foo=bar in your environment will set the foo configuration parameter to bar.
js. method 4: Use cross-env package. This package allows environment variables to be set in one way for every platform. After installing it with npm, you can just add it to your deployment script in package.json as follows: "build:deploy": "cross-env NODE_ENV=production webpack"
In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable. Click Edit to modify an existing environment variable.
In case you use .env
file, let's use grep
or eval
to get a value environment variable from the .env file.
Updated start2
as @Paul suggested:
"scripts": { "start": "NODE_ENV=$(grep NODE_ENV .env | cut -d '=' -f2) some_script", "start2": "eval $(grep '^NODE_ENV' .env) && some_script" }
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