Working Directory

The working directory determines the base path for file system operations and module resolution in your code. By default, PlayJS uses a system-assigned temporary directory. You can change it to any folder on your machine.

Why It Matters

When your code performs file system operations — such as reading or writing files with fs — the paths are resolved relative to the working directory. For example:

import fs from 'fs'

// Reads from <working-directory>/data.json
const data = fs.readFileSync('data.json', 'utf-8')

If you set the working directory to /Users/you/projects/my-app, then data.json resolves to /Users/you/projects/my-app/data.json.

The working directory also affects:

  • Module resolution — Relative import and require paths are resolved from this directory
  • process.cwd() — Returns the current working directory

Setting the Working Directory

Go to the menu Action → Set Working Directory and select a folder. The change takes effect immediately for all subsequent code executions.

Use Cases

  • Working with local files — Point the working directory to a folder containing data files, configuration, or assets you want to read or write
  • Testing Node.js scripts — Set it to your project root so that relative paths and module imports resolve correctly
  • Accessing project resources — Read JSON configs, CSV data, or any files from a specific project folder
© 2026 QI LEI. All rights reserved.