Load package.json data and make it accessible via process.env (similar to npm/yarn scripts)
# with npm
npm install npm-package-to-env
# or with Yarn
yarn add npm-package-to-env
As early as possible in your application, require and configure npm-package-to-env
.
require('npm-package-to-env').config();
This command will place the values defined in your package.json
into environment variables following the same convention as yarn or npm.
{
"name": "my-package",
"config": {
"foo": "bar"
}
}
And then in your app:
require('npm-package-to-env').config();
console.log(process.env.npm_package_name); // 'my-package'
console.log(process.env.npm_package_config_foo); // 'bar'
Thanks to Jess Telford who initially shared the script behavior and the folks who maintain dotenv which I had a look at how they do things. :)
See LICENSE
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!