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' }))
Black and Whitelisting
As an array of strings:
process.env = {
'WILLEM': 'DAFOE',
'MICHAEL': 'DOUGLAS',
}
app.use('/env', expressEnv({ whitelist: ['MICHAEL'] }))
As a function:
process.env = {
'WILLEM': 'DAFOE',
'MICHAEL': 'DOUGLAS',
}
app.use('/env', expressEnv({ blacklist: (value: string, key: string) => key.includes('CH') }))