Intro: Env Variables
Reading environment variables from JavaScript and Python
Many applications use environment variables to pass small bits of data between invocations, or across process boundaries.
As part of Elide's job in unifying multiple languages for use in one program, environment variable access is made uniform across all languages:
Environment is subject to policy. By default, code cannot see system environment variables in Elide; this is a big difference with other runtimes, so it bears repeating below.
Environment is loaded uniformly. Support for features like dotenv files is cross-language in Elide. If you see a variable in JavaScript, you will see it as well in Python, Ruby, and so on.
Before you start
Before running the code below, you'll need to make sure the following is true:
The
elide
binary is executableThe
elide
binary is on yourPATH
, or otherwise referenced in absolute form
Reading environment variables
We're going to try out Elide's policies with regard to reading host environment variables.
Start an interactive session; Elide defaults to JavaScript, so you should get a JavaScript prompt:
export ELIDE_TESTING="hello" elide repl elide (js) >Elide provides the
process
object, just like Node:elide (js) > process.env.ELIDE_TESTING undefinedOur
ELIDE_TESTING
environment variable isn't showing up! That's because Elide forbids access to environment variables by default.Now, let's run the REPL session again, but with access to host environment:
elide repl --allow:host-env elide (js) > process.env.ELIDE_TESTING helloNeat! We can see the environment variable.
Now let's try Python:
elide repl --python elide (python) > import os; os.environ Environ(ELIDE_INTERNAL, ELIDE_ROOT, NODE_ENV)And with environment access enabled:
elide repl --python --allow:host-env elide (python) > import os; os.environ Environ(ANDROID_HOME, AWS_ACCESS_KEY_ID, ... ELIDE_TESTING, ...)Of course, the accessing variable returns the expected value:
elide repl --python --allow:host-env elide (python) > import os; os.environ["ELIDE_TESTING"] 'hello'
What you've learned
In this tutorial, you learned about Elide's policy enforcement around env variable access, and how it interoperates with JavaScript and Python.