How to access local ENV variables in angular js
angularjs, node.js
Solution
You cannot get ENV variables on browser. You can send request to a rest service on your server, and get env on backend, then response back to client
Quick example: (Express.js)
app.get("/rest/getenv", function(req, res) {
var env = process.env.ENV_VARIABLE;
res.json({result: env});
});
Edit:
You need to protect this rest url with token like strings. Or else, anyone can reach that url and get your environment variable value. This can be security concern
Problem
Is it possible to access ENV variables from angularjs? I've got an angular 1.2.8 app being compiled via Brunch.io It's hosted as a basic node app on heroku. (I do compiling locally; then push) I've read a few things about token replacement during the compile stage for ENV variables. However I'd much rather be able to push up the code to several different servers and have it resolve the correct local settings using just the ENV variables. Thanks!