npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cross-platform-system-interaction

v1.0.0

Published

API unificada e simplificada para interagir com funcionalidades nativas do sistema operacional em ambientes Node.js, como gerenciamento de arquivos, controle de processos e informações do sistema.

Downloads

5

Readme

Cross-Platform System Interaction 🖥️

(cross-platform-system-interaction)

NPM Version
NPM Downloads
License: MIT
TypeScript

A unified and simplified API to interact with native operating system functionalities (Windows, macOS, and Linux) in Node.js environments.


🚀 Why use this package?

Many Node.js projects — especially CLI tools, automation utilities, and desktop applications (via Electron) — need to interact deeply with the operating system.

The native Node.js API (fs, child_process, os) is functional but often requires complex conditional logic, such as:

if (process.platform === 'win32') {
  // Windows-specific logic
}

cross-platform-system-interaction abstracts away these differences, providing a consistent interface and advanced features that let you build cross-platform applications more efficiently with less code.


✨ Features

  • Advanced File Management
    Copy, move, delete, change permissions, get metadata, and watch files/directories in real time. Includes helpers for JSON manipulation.

  • Robust Process Control
    Start, monitor, interact with stdin, terminate, and find processes by name or PID.

  • System Information Access
    Get details about CPU, memory usage, network interfaces, platform, hostname, and more.

  • Clipboard Management
    Programmatically copy and paste text with a simple cross-platform API.

  • Typed Error Handling
    Custom error classes (FileError, ProcessError) with detailed context for debugging.


📦 Installation

npm install cross-platform-system-interaction

🔧 Usage

The library is organized into namespaces: file, process, system, and clipboard.

import { file, process, system, clipboard } from 'cross-platform-system-interaction';

📄 1. file Module (File Management)

Read and Write JSON

async function manageConfig() {
  const configPath = './config.json';
  const defaultConfig = { version: 1, theme: 'dark' };

  await file.writeJson(configPath, defaultConfig, { space: 2 });
  console.log('Config file created.');

  const config = await file.readJson(configPath);
  console.log('Current theme:', config.theme);
}

Copy and Remove Files/Directories

async function organizeFiles() {
  const sourceDir = './temp/logs';
  const backupDir = './backup/logs';

  await file.copy(sourceDir, backupDir, { recursive: true });
  console.log(`Logs copied to ${backupDir}`);

  await file.remove(sourceDir, { recursive: true });
  console.log('Temporary logs directory removed.');
}

Watch for Changes

const watcher = file.watch('./src');
watcher.on('change', path => console.log(`File changed: ${path}`));

⚙️ 2. process Module (Process Management)

Execute a Command with Error Handling

import { process as proc, ProcessError } from 'cross-platform-system-interaction';

async function getCurrentBranch() {
  try {
    const { stdout } = await proc.execute('git', ['branch', '--show-current']).finished;
    console.log('Current branch:', stdout.trim());
  } catch (error) {
    if (error instanceof ProcessError) {
      console.error(`Git command failed (Exit Code: ${error.exitCode}):`, error.stderr);
    }
  }
}

Find and Kill a Process

async function manageServer() {
  const nodeProcesses = await proc.findProcessByName('node');
  console.log(`Found ${nodeProcesses.length} 'node' processes.`);

  if (nodeProcesses.length > 0) {
    const pid = nodeProcesses[0];
    await proc.kill(pid);
    console.log('Process terminated.');
  }
}

💻 3. system Module (System Information)

function logSystemInfo() {
  console.log(`Platform: ${system.getPlatform()} (${system.getArch()})`);

  const mem = system.getMemoryUsage();
  console.log(`Memory: ${(mem.usedPercent * 100).toFixed(2)}% of ${(mem.total / 1e9).toFixed(2)} GB`);

  const cpus = system.getCpuInfo();
  console.log(`CPU: ${cpus.length} cores | Model: ${cpus[0].model}`);
}

📋 4. clipboard Module (Clipboard Management)

async function manipulateClipboard() {
  await clipboard.write(`Text copied at: ${new Date().toLocaleTimeString()}`);
  const content = await clipboard.read();
  console.log('Clipboard content:', content);
}

🛑 Error Handling

  • SystemInteractionError: base error for all others.
  • FileError: includes filePath.
  • ProcessError: includes command, exitCode, and stderr.
import { file, FileError } from 'cross-platform-system-interaction';

try {
  await file.readJson('/invalid.json');
} catch (error) {
  if (error instanceof FileError) {
    console.error(`File error at: ${error.filePath}`);
  }
}

📖 Quick API Reference

| Module | Function | Description | |-----------|------------------------|--------------------------------------------| | file | exists(path) | Checks if a file or directory exists. | | | getMetadata(path) | Retrieves file/directory metadata. | | | setPermissions(path) | Changes permissions (chmod). | | | remove(path, opts) | Removes a file or directory. | | | copy(src, dest, opts) | Copies a file or directory. | | | readJson(path) | Reads and parses a JSON file. | | | writeJson(path, data) | Writes an object to a JSON file. | | | watch(path, opts) | Watches for real-time changes. | | process | execute(cmd, args) | Executes a process. | | | kill(pid, force) | Kills a process by PID. | | | findProcessByName(name)| Finds processes by name. | | system | getPlatform() | Returns the OS platform (e.g., win32). | | | getArch() | Returns the CPU architecture (e.g., x64).| | | getMemoryUsage() | Returns memory usage. | | | getCpuInfo() | Returns CPU core info. | | | getNetworkInterfaces() | Returns network interfaces. | | | getHostname() | Returns the system hostname. | | clipboard | read() | Reads clipboard text. | | | write(text) | Writes text to clipboard. |


🤝 Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/new-feature).
  3. Implement your changes + tests.
  4. Open a Pull Request.

📜 License

This project is licensed under the MIT License.