1.0.4 • Published 2 years ago

express-env v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Express-Env

Safely expose your environment variables to dynamically fetch them in the frontend.

import expressEnv from 'express-env'

app.use('/env', expressEnv())
<!DOCTYPE html>
<html>
<head>
  <script src="./env"></script>
</head>
<body>
  <script>
    console.log(window.ENV)
  </script>
</body>
</html>

Configurable Options

Namespace

process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ namespace: 'window.LEAKY_ENVIRONMENT' }))
// GET /env: window.LEAKY_ENVIRONMENT = {"WILLEM":"DAFOE","MICHAEL":"DOUGLAS"}

Black and Whitelisting

As an array of strings:

process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ whitelist: ['MICHAEL'] }))
// GET /env: window.ENV = {"MICHAEL":"DOUGLAS"}

As a function:

process.env = {
  'WILLEM': 'DAFOE',
  'MICHAEL': 'DOUGLAS',
}

app.use('/env', expressEnv({ blacklist: (value: string, key: string) => key.includes('CH') }))
// GET /env: window.ENV = {"WILLEM":"DAFOE"}
1.0.4

2 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago