Skip to content

Latest commit

 

History

History
420 lines (257 loc) · 20 KB

API.md

File metadata and controls

420 lines (257 loc) · 20 KB

Table of Contents

env-universal

src/index.js:10-10

Environment definitions and helpers

Note: in browser runtimes process.env will need to be defined via something like Webpack's DefinePlugin

readEnv

src/index.js:29-85

Given an environment config (defaults to process.env), parse it into a standard environment definition

Parameters

  • config Object (optional, default process.env)
    • config.NODE_ENV String?
    • config.APP_ENV String?
    • config.SERVER any?
    • config.CLIENT any?
    • config.IS_REVIEW_APP any?
    • config.npm_package_version String?
    • config.HOST String?
    • config.PORT String?

Returns Object envDef

envDef

src/index.js:59-82

A standardized environment description

  • see env-universal/constants
  • see env-universal/utils

Properties

env-universal/constants

src/constants.js:7-7

production

src/constants.js:7-7

Production NODE_ENV and/or APP_ENV

Type: string

test

src/constants.js:13-13

Test NODE_ENV

Type: string

ci

src/constants.js:19-19

CI NODE_ENV

Type: string

development

src/constants.js:25-25

Development NODE_ENV

Type: string

qa

src/constants.js:31-31

QA APP_ENV

Type: string

staging

src/constants.js:37-37

Staging APP_ENV

Type: string

preprod

src/constants.js:43-43

Preprod APP_ENV

Type: string

env-universal/utils

src/utils.js:3-3

getAppVersion

src/utils.js:22-22

Get the app version from package.json

Parameters

  • config Object (optional, default {})
    • config.npm_package_version String

Returns String

getEnv

src/utils.js:30-30

Get the application environment, defaults to development

Parameters

  • config Object (optional, default {})

Returns String

getStage

src/utils.js:38-38

Get the application deployment stage

Parameters

  • config Object (optional, default {})

Returns String?

isDev

src/utils.js:46-46

Is the application in development mode?

Parameters

  • config Object (optional, default {})

Returns Boolean

isDeployed

src/utils.js:54-54

Is the application deployed (NODE_ENV=production)

Parameters

  • config Object (optional, default {})

Returns Boolean

isCI

src/utils.js:62-62

Is the application in CI mode?

Parameters

  • config Object (optional, default {})

Returns Boolean

isTest

src/utils.js:70-70

Is the application in test mode?

Parameters

  • config Object (optional, default {})

Returns Boolean

isQA

src/utils.js:78-78

Is the application a qa deployment?

Parameters

  • config Object (optional, default {})

Returns Boolean

isStaging

src/utils.js:86-86

Is the application a staging deployment?

Parameters

  • config Object (optional, default {})

Returns Boolean

isPreProd

src/utils.js:94-94

Is the application a preprod deployment?

Parameters

  • config Object (optional, default {})

Returns Boolean

isProduction

src/utils.js:102-102

Is the application a production deployment?

Parameters

  • config Object (optional, default {})

Returns Boolean

isHerokuReviewApp

src/utils.js:110-110

Is the application a heroku review app deployment?

Parameters

  • config Object (optional, default {})
    • config.IS_REVIEW_APP any

Returns Boolean

isServer

src/utils.js:118-118

Is the application running in a server runtime?

Parameters

  • config Object (optional, default {})
    • config.SERVER any

Returns Boolean

isClient

src/utils.js:126-126

Is the application running in a client runtime?

Parameters

  • config Object (optional, default {})
    • config.CLIENT any

Returns Boolean

getPublicEnv

src/utils.js:146-149

When building universal apps, it is common for a Node process to have sensitive information stored as environment variables. This isn't acceptable for client bundles, since they would be output in plaintext.

This utility serves to whitelist public keys. It's output is meant for use with dotenv and something like webpack.DefinePlugin

Parameters

  • publicKeys Array<String> keys from Node process.env to inject into a client bundle
  • config Object (optional, default process.env)

Examples

see `test/browser/webpack.config`, and the `npm run test:browser` target

Returns Object stringified object extracted from process.env

getHerokuMetadata

src/utils.js:166-171

This is only useful for applications running on heroku with the runtime-dyno-metadata labs feature enabled and is not included in the default output of env

Parameters

  • config Object (optional, default {})
    • config.HEROKU_APP_NAME String The application name. "example-app"
    • config.HEROKU_RELEASE_CREATED_AT String The time and date the release was created. "2015-04-02T18:00:42Z"
    • config.HEROKU_RELEASE_VERSION String The identifier for the current release. "v42"
    • config.HEROKU_SLUG_COMMIT String The commit hash for the current release. "2c3a0b24069af49b3de35b8e8c26765c1dba9ff0"

Returns Object

env-universal/serverUtils

src/serverUtils.js:3-3

serverHost

src/serverUtils.js:14-14

Get the server host. Defaults to '0.0.0.0'

Parameters

Returns String

serverPort

src/serverUtils.js:23-23

Get the server port. Defaults to '8080'

Parameters

Returns String