Environment:AI QL Tuui Node FS
| Knowledge Sources | |
|---|---|
| Domains | Node.js, File_System, Configuration |
| Last Updated | 2026-10-24 20:38 GMT |
Overview
Node.js file system module environment providing synchronous and watched file I/O for MCP and LLM configuration loading.
Description
The Node.js fs module is used in the Electron main process for reading configuration files (MCP server configs, LLM provider configs, popup templates, startup configs), writing MCPB bundle files, and watching configuration files for hot-reload. tuui uses synchronous readFileSync for config loading, writeFileSync for bundle file persistence, existsSync and statSync for path validation, readdirSync for manifest discovery, mkdirSync for directory creation, and fs.watch for config file change detection with debounced re-loading.
Usage
Use this environment for any main-process implementation that reads, writes, or watches files on disk. The config loader (loadConfigFile) and MCPB bundle operations rely on this environment.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Runtime | Node.js >= 22.12.0 | fs is a built-in module
|
| OS | macOS, Windows, or Linux | Path handling uses path module for cross-platform support
|
| Disk | Read/write access to assets directory | Config files and MCPB bundles stored under ASSETS_PATH
|
Dependencies
Node.js Built-in Modules
- `fs` — File reading, writing, watching, directory listing
- `path` — Path resolution, joining, normalization, separator handling
No External NPM Packages Required
fs and path are Node.js built-in modules.
Third-Party Utilities
- `lodash` >= 4.17.x —
debouncefor file watcher
Credentials
No credentials required.
Quick Install
# fs and path are Node.js builtins; no install needed
# Only lodash is needed for debounce:
npm install lodash
Code Evidence
Config file reading from `src/main/mcp/config.ts:25-32`:
import fs from 'node:fs'
import path from 'node:path'
function readConfig(configPath: string) {
const fileString = fs.readFileSync(configPath, 'utf8')
if (fileString) {
return JSON.parse(fileString)
} else {
return {}
}
}
File watching with debounce from `src/main/mcp/config.ts:48-51`:
fs.watch(resolvedConfigPath, () => {
if (timeoutId) clearTimeout(timeoutId)
timeoutId = setTimeout(() => debouncedHandleFileChange(resolvedConfigPath), DEBOUNCE_DELAY)
})
Bundle file writing from `src/main/IPCs.ts:207`:
writeFileSync(filePath, buffer, { encoding: null })
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `MCP Config Not Found` | Config file path does not exist | Check Constants.ASSETS_PATH.mcp path
|
| `MCP Config JSON parse failure` | Malformed JSON in config file | Validate JSON syntax; fix and save |
| `ENOENT: no such file or directory` | Directory for bundle not created | mkdirSync(dirPath, { recursive: true }) is called before write
|
Compatibility Notes
- Path resolution: Uses
path.isAbsoluteto handle both absolute and relative paths. Relative paths resolved againstprocess.cwd(). - File watching:
fs.watchbehavior varies by OS; debounced (500ms) to handle rapid editor saves. - Packaged app: Asset paths differ —
app.isPackagedswitches toprocess.resourcesPath.