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

@termuijs/data

v0.1.7

Published

System data providers for TermUI: CPU, memory, disk, processes, network

Downloads

581

Readme

@termuijs/data

Real-time system metrics for TermUI. CPU, memory, disk, network, processes, and HTTP health; available as raw function calls or as reactive hooks for JSX components.

Install

npm install @termuijs/data

Raw API

Call these functions directly for one-shot reads:

import { cpu, memory, disk, network, processes, system } from '@termuijs/data'

// CPU
console.log(cpu.percent)    // 45.2
console.log(cpu.cores)      // 8

// Memory
console.log(memory.used)    // bytes
console.log(memory.total)   // bytes
console.log(memory.percent) // 67.1

// Disk
console.log(disk.percent)   // 52.3

// Top processes by CPU
const top = processes.top(5)
// [{ name: 'node', pid: 1234, cpu: 12.3, mem: 5.6 }, ...]

// Network throughput
console.log(network.rx)  // bytes/sec received
console.log(network.tx)  // bytes/sec transmitted

// System info (static)
console.log(system.hostname)
console.log(system.platform)
console.log(system.uptime)

Reactive hooks

Use these inside JSX components. Each hook polls on an interval and triggers a re-render when data changes. All hooks clean up their intervals on component unmount.

import {
    useCpu,
    useMemory,
    useDisk,
    useNetwork,
    useTopProcesses,
    useSystemInfo,
    useHttpHealth,
} from '@termuijs/data'

function CpuMonitor() {
    const cpu = useCpu(500)  // refresh every 500ms
    return <gauge label="CPU" value={cpu.usage / 100} />
}

function SystemDashboard() {
    const cpu  = useCpu(1000)
    const mem  = useMemory(1000)
    const disk = useDisk(5000)
    const top  = useTopProcesses(5, 2000)
    const info = useSystemInfo()  // fetched once; static

    return (
        <Box flexDirection="column">
            <Text>Host: {info.hostname}</Text>
            <Text>CPU: {cpu.usage.toFixed(1)}%</Text>
            <Text>MEM: {(mem.used / mem.total * 100).toFixed(1)}%</Text>
        </Box>
    )
}

HTTP health checks

import { useHttpHealth } from '@termuijs/data'

function HealthPanel() {
    const checks = useHttpHealth(
        ['https://api.example.com/health', 'https://db.example.com/ping'],
        5000,  // check every 5 seconds
    )

    return (
        <Box flexDirection="column">
            {checks.map((c) => (
                <Text key={c.url} color={c.status === 200 ? 'green' : 'red'}>
                    {c.url}: {c.status} ({c.latencyMs}ms)
                </Text>
            ))}
        </Box>
    )
}

Hook reference

| Hook | Default interval | Returns | |------|-----------------|---------| | useCpu(ms?) | 1000ms | { usage, cores, model } | | useMemory(ms?) | 1000ms | { used, total, free, percent } | | useDisk(ms?) | 5000ms | { used, total, free, percent } | | useNetwork(ms?) | 1000ms | { rx, tx, interface } | | useTopProcesses(n, ms?) | 2000ms | Array<{ name, pid, cpu, mem }> | | useSystemInfo() | once | { hostname, platform, arch, uptime } | | useHttpHealth(urls, ms?) | 5000ms | Array<{ url, status, latencyMs }> |

Raw collectors vs hooks

Raw collectors (cpu.percent, memory.used, etc.) do not clean up. Use them in one-shot scripts or outside component trees. Use hooks inside JSX components; they register cleanup on unmount automatically.

Documentation

Full docs at www.termui.io/docs/data/overview.

License

MIT



Data fetching guide

@termuijs/data includes reactive hooks for fetching remote data inside TermUI components. Each hook integrates with the TermUI render loop — updates trigger re-renders automatically. No manual subscription management is needed.

Overview

The data-fetching hooks follow the same reactive model as the system-metric hooks (useCpu, useMemory, etc.) already in this package. Each hook returns a plain object whose fields update when new data arrives, and the component re-renders only when the values it reads change.

Four primitives cover the most common patterns:

| Hook | Use case | | --- | --- | | useFetch | One-shot HTTP request on mount, with optional caching | | usePolling | Repeatedly call an async function on a fixed interval | | useSSE | Streaming updates over a Server-Sent Events connection | | invalidate | Drop a cached response to force the next useFetch to re-fetch |


useFetch

useFetch fires an HTTP GET request when the component mounts and exposes the result reactively. Pass staleTime to cache the response in memory and skip the network on subsequent mounts while the entry is still fresh.

import { useFetch } from '@termuijs/data'
import type { UseFetchOptions, UseFetchResult } from '@termuijs/data'

function PriceWidget() {
    const options: UseFetchOptions = { staleTime: 30_000 } // cache 30 s

    const result: UseFetchResult<{ price: number }> =
        useFetch<{ price: number }>('https://api.example.com/price', options)

    if (result.loading) return <Text>Loading…</Text>
    if (result.error)   return <Text color="red">{result.error.message}</Text>

    return <Text>Price: {result.data?.price}</Text>
}

UseFetchOptions fields:

| Field | Type | Description | | --- | --- | --- | | staleTime | number | How long (ms) a cached response stays fresh (default 0) |

UseFetchResult<T> fields:

| Field | Type | Description | | --- | --- | --- | | data | T \| null | Parsed response body, or null while loading | | error | Error \| null | Set if the request failed, otherwise null | | loading | boolean | true while the request is in flight |


Polling

usePolling repeatedly executes an async function on a fixed interval. Pass any async function that returns data — it is not limited to HTTP requests.

import { usePolling } from '@termuijs/data'
import type { UsePollingResult } from '@termuijs/data'

function StockTicker() {
    const result: UsePollingResult<{ symbol: string; bid: number }[]> =
        usePolling(
            () => fetch('https://api.example.com/quotes').then(r => r.json()),
            5_000, // repeat every 5 seconds
        )

    if (result.loading) return <Text>Connecting…</Text>

    return (
        <Box flexDirection="column">
            {result.data?.map((q) => (
                <Text key={q.symbol}>{q.symbol}: {q.bid}</Text>
            ))}
            {result.error && <Text color="red">{result.error.message}</Text>}
        </Box>
    )
}

UsePollingResult<T> fields:

| Field | Type | Description | | --- | --- | --- | | data | T \| null | Last successful return value, or null before first success | | error | Error \| null | Last error, if any; polling continues regardless | | loading | boolean | true until the first execution completes |


SSE

useSSE opens a persistent Server-Sent Events connection and pushes each received event into data. The connection closes automatically when the component unmounts or url changes. An optional parse function lets you deserialise the raw event string into a typed value.

import { useSSE } from '@termuijs/data'
import type { UseSSEResult } from '@termuijs/data'

interface LogLine {
    ts: number
    level: string
    msg: string
}

function LiveLog() {
    const result: UseSSEResult<LogLine> = useSSE<LogLine>(
        'https://api.example.com/logs/stream',
        (raw) => JSON.parse(raw) as LogLine,
    )

    if (result.loading) return <Text>Connecting…</Text>

    return (
        <Box flexDirection="column">
            {result.error && <Text color="red">{result.error.message}</Text>}
            {result.data && (
                <Text>[{result.data.level}] {result.data.msg}</Text>
            )}
        </Box>
    )
}

UseSSEResult<T> fields:

| Field | Type | Description | | --- | --- | --- | | data | T \| null | Most recent parsed event payload, or null before first event | | error | Error \| null | Set if the connection failed, otherwise null | | loading | boolean | true until the first event is received |


Caching

useFetch caches responses in memory keyed by URL. A cached entry is reused as long as it is younger than staleTime. Once the entry expires, the next render re-fetches automatically.

To drop a cached entry early — for example after a write — call invalidate:

import { useFetch, invalidate } from '@termuijs/data'

function TodoList() {
    const result = useFetch<{ id: number; title: string }[]>(
        '/api/todos',
        { staleTime: 60_000 },
    )

    async function addTodo(title: string) {
        await fetch('/api/todos', {
            method: 'POST',
            body: JSON.stringify({ title }),
        })
        // drop the cached list so the next render re-fetches
        invalidate('/api/todos')
    }

    // …
}

invalidate(key: string): void removes the cache entry for the given URL and cancels any in-flight de-duplicated request for that key. Any mounted component using the same URL will re-fetch on its next render. Calling invalidate with a key that has no cached entry is a no-op.