npm-package-to-env

1.0.1 • Public • Published

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!

Readme

Keywords

Package Sidebar

Install

npm i npm-package-to-env

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

14.5 kB

Total Files

10

Last publish

Collaborators

  • stefanjudis