Skip to content

Load package.json data and make them accessible via process.env

License

Notifications You must be signed in to change notification settings

stefanjudis/npm-package-to-env

Repository files navigation

Build Status codecov All Contributors

npm-package-to-env

Load package.json data and make it accessible via process.env (similar to npm/yarn scripts)

Install

# with npm
npm install npm-package-to-env

# or with Yarn
yarn add npm-package-to-env

Usage

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

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. :)

License

See LICENSE

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Load package.json data and make them accessible via process.env

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published