UNPKG

@northscaler/config-custom-environment-variables-generator

Version:

Generator of config/custom-environment-variables.json File for config-Based Projects

126 lines (89 loc) 4.36 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Home</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Home</h1> <h3> </h3> <section> <article><h1>Node.js Custom Environment Variables Generator for <code>config</code>-Based Projects</h1> <p>This is a handy little utility that will generate JSON suitable for use as a <a href="https://www.npmjs.com/package/config"><code>config</code></a> -based project's <code>config/custom-environment-variables.json</code>. (Note that throughout this project &quot;cev&quot; stands for &quot;custom environment variables&quot;.)</p> <blockquote> <p>NOTE: This package supercedes <a href="https://www.npmjs.com/package/config-cev-generator">https://www.npmjs.com/package/config-cev-generator</a></p> </blockquote> <p>See <a href="http://www.scispike.com/blog/get-rid-of-node-js-config-grunt-work">this blog post</a> for full description and tips.</p> <p>It really comes in handy when your configuration starts to get big and you forget to keep your <code>config/custom-environment-variables.json</code> file in sync with the rest of your configuration.</p> <blockquote> <p>NOTE: If you're using TypeScript, make sure <code>ts-node</code> is on your <code>PATH</code> and that you use <code>cev-ts</code> instead of <code>cev</code>.</p> </blockquote> <h2>Example</h2> <pre class="prettyprint source"><code># cd into a config-based Node.js project... $ npm install --save-dev @northscaler/config-custom-environment-variables-generator $ npx cev </code></pre> <p>If your project's configuration is</p> <pre class="prettyprint source"><code>{ &quot;foo&quot;: { &quot;bar&quot;: &quot;snafu&quot;, &quot;goo&quot;: &quot;juju&quot; } } </code></pre> <p>then the preceding command will generate JSON to stdout suitable for use as your project's <code>config/custom-environment-variables.json</code>:</p> <pre class="prettyprint source"><code>{ &quot;foo&quot;: { &quot;bar&quot;: &quot;NODE_APP_FOO_BAR&quot;, &quot;goo&quot;: &quot;NODE_APP_FOO_GOO&quot; } } </code></pre> <p>In order to support <code>config</code>'s <code>__format</code> feature, see the following example. If your project's configuration is</p> <pre class="prettyprint source"><code>{ &quot;foo&quot;: { &quot;bar&quot;: 1, &quot;goo&quot;: 2 }, &quot;snafu&quot;: &quot;something&quot; } </code></pre> <p>then the following command will cause your configuration's <code>foo.bar</code> value to use format <code>json</code> and <code>foo.goo</code> to use <code>number</code>:</p> <pre class="prettyprint source"><code>npx cev -k foo.bar=json -k foo.goo=number </code></pre> <p>The CLI writes to stdout by default. To save the output, just direct it to a file:</p> <p><code>$ npx cev &gt; config/custom-environment-variables.json</code></p> <p>... or give the file as the sole positional argument:</p> <p><code>$ npx cev config/custom-environment-variables.json</code></p> <h2>Prerequisites</h2> <p>The generator requires that your project have a valid <code>config</code>-based configuration in order to work properly.</p> <h2>Tips</h2> <ul> <li>The default environment variable prefix is <code>NODE_APP</code>. Customize with <code>-p</code> or <code>--prefix</code>.</li> <li>The default word separator is <code>_</code>. Customize with <code>-s</code> or <code>--separator</code>.</li> <li>Run <code>cev --help</code> for more information.</li> </ul></article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#generate">generate</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sat Jan 15 2022 05:15:30 GMT+0000 (Coordinated Universal Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>