Working directory
Run a tab inside a folder on your Mac, so relative imports, node_modules and .env resolve there.
By default a tab isn’t tied to any folder. Give it a working directory, and it runs as if it lived in that folder.
Set a working directory
Point a tab at a folder and relative imports, files and process.cwd() resolve there.
Choose Actions → Set Working Directory…, or click the working-directory button in the status bar, and pick a folder. It’s also Set Working Directory… in the command palette.
Each tab has its own working directory, and it’s kept with the tab across relaunches.
What changes
With a working directory set:
<working directory>/node_modulesis searched before JSLab’s own installed packages.process.cwd(),__dirnameandimport.meta.dirare that folder, and relative imports written as string literals resolve there.__filenameandimport.meta.pathare<working directory>/<tab title>.<extension>.- A
.envfile in that folder is loaded into the run. See Environment variables. - The status bar shows the folder’s name. Click it to change the folder.
import { readFile } from "node:fs/promises";
import config from "./config.json";
config; // read from the working directory
await readFile("./README.md", "utf8");
Clear it
Choose Actions → Clear Working Directory, or click the × beside the folder’s name in the status bar.
If the folder goes missing
If the folder is moved or deleted, the status bar marks it as not found, and a run reports Working directory not found with a Change… button to pick another folder.
From a terminal
jslab --cwd <dir> opens a file in a new tab with that working directory. See The jslab CLI.