expose-env-middleware
Express middleware to dynamically expose environment variables to client-side code via window.process.env
:
// server.js const app = const exposeEnvMiddleware = // Pass it a function that returns env varsconst getEnv = FOO: 'bar' appapp
<!-- index.html -->
This setup allows env vars to reload each time index.html is fetched.
API
-
middleware(getEnv[, options])
getEnv
: A function that returns an object of env variables.options.template
(optional, default=defaultTemplate
) Template function for serializing the env object into a file. Default is shown below:
{return `window.process = {env:}`}