npm-package-env
conveniently use
npm_package_
variables using property accessors
installation
npm i npm-package-env -S
overview
provides easy access to per-package config settings (or package variables) via a virtual object.
API
.<property>
/ [<'property-name'>]
(property accessors)
get
retrieves the current value or walks deeper into the npm_package_
tree.
equivalent to stating the full variable path in process.env.npm_package_<var_path>
.
Returns: {String|I}
the current value, if exists, or a chainable
object, bound to the new namespace.
set
sets a new value in the specified namespace, coerced to a string.
equivalent to assigning a variable value to process.env.npm_package_<var_path>
.
examples
all examples assume npm-script.js
is run via npm run
, i.e. the
package.json
has something like this:
"scripts":
getting / setting a value
npm-script.js
const npmEnv = ;npmEnvconfig'dev-server'port; // -> '7777'npmEnvconfig'dev-server'port = 9999;npmEnvconfig'dev-server'port; // -> '9999'
package.json
"config":
getting / setting a value inside an array
npm-script.js
const npmEnv = ;npmEnvkeywords1; // -> 'bar'npmEnvkeywords1 = 'wow';npmEnvkeywords1; // -> 'wow'
package.json
"keywords":
getting / setting a value inside an object
npm-script.js
const npmEnv = ;npmEnvdependencies'auto-exports'; // -> '14.1.3'npmEnvdependencies'auto-exports' = '~2.0.1';npmEnvdependencies'auto-exports'; // -> '~2.0.1'
package.json
"dependencies":