Expose Node.js global process.env to compiled client-side code
$ npm install --save duo-env
// file: app.js
var env = require('env').NODE_ENV
var uri = env === 'prod' ? 'api.foobar.io' : 'localhost:8000'
// ...
NODE_ENV=prod duo app.js > build/app.js --use duo-env
# Now "uri" in compiled app will equal 'api.foobar.io'
The following settings are available:
name
– the literal module name that will be exposed, eg: what you want torequire(NAME)
. Defaults to "env".pick
– expose only a subset ofprocess.env
. The exposed module is still a hash, but does not include the huge amount of things thatprocess.env
has even by default.
Currently these settings are only useable in a scripted duo context, but I want to make it possible to pass these on the CLI too: duojs/duo#362