Environment variables
Set variables every tab's run sees, paste a whole .env file at once, and learn the order the layers apply in.
The Environment Variables sheet
Choose Tools → Environment Variables…, or run it from the command palette. It has no default shortcut. The sheet holds key and value pairs that every tab’s run sees, on top of what your login shell already exports.
- Type a key and a value, click Add, then Save.
- A key must start with a letter or underscore, and use only letters, digits and underscores. Each key can appear once.
- You can store up to 500 variables.
- Values are masked. Show and Hide reveal or mask one.
- Changes apply from the next run. A run already in progress keeps its old environment.
Paste a .env file
Paste a whole .env file into the Key field to add several variables at once. JSLab parses it and fills in the rows for you to check before you save.
API_URL=https://api.example.com
API_TOKEN=abc123
Reading them in your code
Set variables once in Tools → Environment Variables, and every run reads them from process.env.
process.env.JSLAB;
process.env.SHELL;
process.env.API_URL ?? "API_URL isn't set yet: add it in Tools → Environment Variables…";
process.env.API_URL;
process.env.JSLAB; // "1" in every JSLab run
Layering
For a run in the Bun runtime, the environment is built in this order, with later layers winning:
- Your login shell’s environment.
- The variables in the Environment Variables sheet.
- The working directory’s
.envfile, if the tab has a working directory. JSLAB=1, set on every run so your code can tell it’s running inside JSLab.
JSLab’s own JSLAB_* variables and BUN_OPTIONS never reach a run, whichever layer they came from.
A working folder’s .env is read only up to 1 MiB. JSLab parses it itself, rather than leaving it to Bun, so the result is the same in every run.
Where they’re stored
Variables are saved in env.json in JSLab’s data folder, created so that only your user account can read it. See Troubleshooting for where the data folder is.