Package Exports
- browser-env
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (browser-env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
browser-env
Share process.env variables with the browser
What?
No. I'm not dumping the whole thing down. Here's how it goes.
Set your env vars with BROWSER_ENV
as a list of comma separated variables you want to share
API_ROOT=https://api.example.com
OTHER_API=https://api.other.com
MY_SECRET=12345
BROWSER_ENV=API_ROOT,OTHER_API
Now in the browser you can access those:
var env = require("browser-env");
console.log(env("API_ROOT"));
// https://api.example.com
console.log(env("MY_SECRET"));
// undefined
Usage
Just add the middleware:
/**
* Module dependencies
*/
var express = require("express")
, env = require("browser-env");
/**
* Expose the app
*/
var app = module.exports = express();
app.use(env());
app.get("/", function(req, res){
res.render("index");
});
On the client side you can either install the component
version or use the standalone in the build
folder.
Component
$ component install CamShaft/browser-env
var env = require("browser-env");
console.log(env());
Standalone
console.log(window.env());