New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

expose-env-middleware

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expose-env-middleware

Expose env variables to client-side code via express

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

expose-env-middleware

Express middleware to dynamically expose environment variables to client-side code via window.process.env:

// server.js

const app = require('express')()
const exposeEnvMiddleware = require('expose-env-middleware')

// Pass it a function that returns env vars
const getEnv = () => ({ FOO: 'bar' })
app.get('/env', exposeEnvMiddleware(getEnv))
app.listen(...)
<!-- index.html -->

<script src="/env"></script>
<script> console.log(process.env.FOO) // -> 'bar' </script>

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:
    function defaultTemplate (env) {
      return `
        window.process = {
          env: ${ JSON.stringify(env) }
        }  
      `
    }
    

FAQs

Package last updated on 11 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts