System API Complete Reference

Version Compatibility: XyPriss v6.0.0 and above

Overview

This document provides a complete reference of all methods available in the XyPriss System API (__sys__). The API is organized into logical categories for easy navigation.

Quick Navigation


Configuration & Metadata

Properties

PropertyTypeDescription
__version__stringApplication version (semver)
__name__stringApplication name
__alias__stringShort application alias
__author__stringApplication author
__description__stringApplication description
__app_urls__Record<string, string>Application URLs map
__port__ / __PORT__numberServer port (synchronized)
__env__stringEnvironment mode
__root__stringProject root path

Methods

MethodReturnsDescription
$update(data)voidMerge configuration data
$add(key, value)voidAdd custom property
$get<T>(key, default?)TGet configuration value
$has(key)booleanCheck if key exists
$remove(key)booleanRemove custom property
$keys()string[]List configuration keys
$toJSON()Record<string, any>Serialize to JSON
$reset()voidReset to defaults
$clone()XyPrissSysCreate independent copy

Environment Helpers

MethodReturnsDescription
$isProduction()booleanCheck if production env
$isDevelopment()booleanCheck if development env
$isStaging()booleanCheck if staging env
$isTest()booleanCheck if test env
$isEnvironment(name)booleanCheck custom environment

Documentation: Configuration Management


Environment Management

__ENV__ Object

MethodReturnsDescription
__ENV__.get(key, default?)string | undefinedGet environment variable
__ENV__.set(key, value)voidSet environment variable
__ENV__.has(key)booleanCheck if variable exists
__ENV__.delete(key)voidRemove environment variable
__ENV__.all()NodeJS.ProcessEnvGet all variables

Documentation: Environment Variables


System Monitoring

System Information

MethodReturnsDescription
$info()SystemInfoComplete system information
$cpu(cores?)CpuUsage | CpuInfo[]CPU usage statistics
$memory()MemoryInfoMemory usage statistics
$uptime()numberSystem uptime in seconds
$bootTime()numberBoot time (Unix timestamp)
$loadAverage()LoadAverageSystem load averages

SystemInfo Structure

interface SystemInfo {
    hostname: string;
    os_name: string;
    os_version: string;
    os_edition: string;
    kernel_version: string;
    architecture: string;
    cpu_count: number;
    cpu_brand: string;
    cpu_vendor: string;
    cpu_frequency: number;
    total_memory: number;
    used_memory: number;
    available_memory: number;
    total_swap: number;
    used_swap: number;
    uptime: number;
    boot_time: number;
    load_average: LoadAverage;
}

Documentation:


Process Management

MethodReturnsDescription
$processes(options?)ProcessInfo[] | ProcessInfoGet process information
$processes({ pid })ProcessInfoGet specific process
$processes({ topCpu: N })ProcessInfo[]Top N CPU consumers
$processes({ topMem: N })ProcessInfo[]Top N memory consumers

ProcessInfo Structure

interface ProcessInfo {
    pid: number;
    name: string;
    exe?: string;
    cmd: string[];
    cpu_usage: number;
    memory: number;
    virtual_memory: number;
    status: string;
    start_time: number;
    run_time: number;
    parent_pid?: number;
    user_id?: string;
    disk_read: number;
    disk_write: number;
}

Documentation: Process Management


Network & Connectivity

MethodReturnsDescription
$network(interface?)NetworkStats | NetworkInterfaceNetwork statistics
$ports(options?)PortInfo[]List open ports

NetworkStats Structure

interface NetworkStats {
    total_received: number;
    total_transmitted: number;
    download_speed: number;
    upload_speed: number;
    interfaces: NetworkInterface[];
}

interface NetworkInterface {
    name: string;
    received: number;
    transmitted: number;
    packets_received: number;
    packets_transmitted: number;
    errors_received: number;
    errors_transmitted: number;
    mac_address: string;
    ip_addresses: string[];
}

Documentation: Network Statistics


Disk & Storage

MethodReturnsDescription
$disks(mountPoint?)DiskInfo[] | DiskInfoDisk information
$du(path)DirUsageDirectory usage statistics

DiskInfo Structure

interface DiskInfo {
    name: string;
    mount_point: string;
    file_system: string;
    total_space: number;
    available_space: number;
    used_space: number;
    usage_percent: number;
    is_removable: boolean;
    disk_type: string;
}

Documentation: Disk Information


Path Operations

MethodReturnsDescription
$resolve(path)stringResolve to absolute path
$join(...paths)stringJoin path segments
$dirname(path)stringGet directory name
$basename(path)stringGet file name
$extname(path)stringGet file extension
$normalize(path)stringNormalize path
$relative(from, to)stringGet relative path
$isAbsolute(path)booleanCheck if absolute

Examples:

__sys__.$resolve("./config.json"); // "/project/config.json"
__sys__.$join("src", "utils", "file.ts"); // "src/utils/file.ts"
__sys__.$dirname("/path/to/file.txt"); // "/path/to"
__sys__.$basename("/path/to/file.txt"); // "file.txt"
__sys__.$extname("file.txt"); // ".txt"

File I/O

Reading

MethodReturnsDescription
$read(path)stringRead file as text
$readBytes(path)BufferRead file as bytes
$readJson(path)anyRead and parse JSON
$readJsonSafe(path, default)anyRead JSON with fallback
$readLines(path)string[]Read file as lines
$readNonEmptyLines(path)string[]Read non-empty lines

Writing

MethodReturnsDescription
$write(path, data)voidWrite text to file
$writeBytes(path, data)voidWrite bytes to file
$writeJson(path, data)voidWrite JSON (pretty)
$writeJsonCompact(path, data)voidWrite JSON (compact)
$writeIfNotExists(path, data)booleanWrite only if new
$append(path, data)voidAppend to file
$appendLine(path, line)voidAppend line to file

Examples:

// Read operations
const text = __sys__.$read("config.txt");
const json = __sys__.$readJson("data.json");
const lines = __sys__.$readLines("log.txt");

// Write operations
__sys__.$write("output.txt", "Hello World");
__sys__.$writeJson("data.json", { key: "value" });
__sys__.$appendLine("log.txt", "New entry");

Directory Management

MethodReturnsDescription
$mkdir(path)voidCreate directory (recursive)
$ensureDir(path)voidEnsure directory exists
$ls(path)string[]List directory contents
$lsFullPath(path)string[]List with full paths
$lsDirs(path)string[]List directories only
$lsFiles(path)string[]List files only
$lsRecursive(path)string[]List recursively
$emptyDir(path)voidRemove all contents

Examples:

__sys__.$mkdir("new/nested/directory");
const files = __sys__.$ls("src");
const dirs = __sys__.$lsDirs("src");
const allFiles = __sys__.$lsRecursive("src");

File Metadata

Existence & Type Checks

MethodReturnsDescription
$exists(path)booleanCheck if path exists
$isFile(path)booleanCheck if file
$isDir(path)booleanCheck if directory
$isSymlink(path)booleanCheck if symbolic link
$isEmpty(path)booleanCheck if empty
$check(path)PathCheckComprehensive check

File Information

MethodReturnsDescription
$stats(path)FileStatsGet file statistics
$size(path, options?)number | stringGet file size
$sizeHuman(path)stringGet human-readable size
$createdAt(path)DateGet creation time
$modifiedAt(path)DateGet modification time
$accessedAt(path)DateGet access time

FileStats Structure

interface FileStats {
    size: number;
    is_file: boolean;
    is_dir: boolean;
    is_symlink: boolean;
    modified: number;
    created: number;
    accessed: number;
    readonly: boolean;
    permissions: number;
}

Examples:

if (__sys__.$exists("file.txt")) {
    const stats = __sys__.$stats("file.txt");
    const size = __sys__.$sizeHuman("file.txt");
    const modified = __sys__.$modifiedAt("file.txt");
}

Search & Discovery

File Search

MethodReturnsDescription
$find(path, pattern)string[]Find by regex pattern
$findByExt(path, ext)string[]Find by extension
$findByPattern(path, glob)string[]Find by glob pattern

Content Search

MethodReturnsDescription
$grep(path, pattern)SearchMatch[]Search in files
$searchInFiles(path, query)SearchMatch[]Text search in files

SearchMatch Structure

interface SearchMatch {
    file: string;
    line: number;
    content: string;
}

Examples:

// Find TypeScript files
const tsFiles = __sys__.$findByExt("src", "ts");

// Find files matching pattern
const configs = __sys__.$find(".", ".*\\.config\\..*");

// Search for text in files
const matches = __sys__.$grep("src", "TODO");
matches.forEach((m) => {
    console.log(`${m.file}:${m.line}: ${m.content}`);
});

Advanced Operations

File Operations

MethodReturnsDescription
$copy(src, dest)voidCopy file or directory
$move(src, dest)voidMove/rename file
$rename(src, dest)voidAlias for $move
$duplicate(src, dest)voidDuplicate file
$rm(path)voidRemove file or directory
$rmIfExists(path)voidRemove if exists
$touch(path)voidCreate or update timestamp

Comparison & Validation

MethodReturnsDescription
$hash(path)stringCalculate SHA-256 hash
$verify(path, hash)booleanVerify file hash
$isSameContent(path1, path2)booleanCompare file contents
$isNewer(path1, path2)booleanCompare modification times

Permissions (Unix)

MethodReturnsDescription
$chmod(path, mode)voidChange permissions

Examples:

// File operations
__sys__.$copy("source.txt", "backup.txt");
__sys__.$move("old.txt", "new.txt");
__sys__.$rm("temp.txt");

// Validation
const hash = __sys__.$hash("file.txt");
const valid = __sys__.$verify("file.txt", hash);

// Comparison
if (__sys__.$isNewer("file1.txt", "file2.txt")) {
    console.log("file1.txt is newer");
}

// Permissions (Unix only)
__sys__.$chmod("script.sh", "755");

Type Definitions

All types are exported from the main package:

import type {
    SystemInfo,
    CpuInfo,
    CpuUsage,
    MemoryInfo,
    DiskInfo,
    NetworkStats,
    NetworkInterface,
    ProcessInfo,
    ProcessStats,
    FileStats,
    SearchMatch,
    PathCheck,
} from "xypriss";

Error Handling

All methods may throw XyPrissError on failure:

import { XyPrissError } from "xypriss";

try {
    const content = __sys__.$read("file.txt");
} catch (error) {
    if (error instanceof XyPrissError) {
        console.error(`Operation failed: ${error.message}`);
    }
}

Performance Considerations

Synchronous Operations

All System API methods are synchronous and will block the event loop:

// This blocks until complete
const files = __sys__.$lsRecursive("large-directory");

// For large operations, consider running in worker threads

Caching Recommendations

Cache results for frequently accessed data:

// Cache system info (changes rarely)
const systemInfo = __sys__.$info();

// Cache file lists (update periodically)
const fileCache = new Map<string, string[]>();

Platform Support

FeatureLinuxmacOSWindows
System Info
CPU Monitoring
Memory Stats
Network Stats
Process Info
Disk Info
File Operations
PermissionsPartial

Related Documentation


Version: XyPriss v6.0.0+
Last Updated: 2026-01-12