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

@hile/micro

v4.1.0

Published

<!-- Generated by scripts/build-ai-context.mjs from docs/ai. Do not edit by hand. -->

Readme

@hile/micro

Run registry-backed service discovery, RPC, streaming RPC, and pub/sub between Node services.

This README is intentionally short and example-first. The complete AI-facing guide ships in AI.md in this package.

When To Use

Use the message packages for request/response messaging over WebSocket, process IPC, worker threads, file-system message handlers, service discovery, streaming RPC, and registry-backed pub/sub.

Install

pnpm add @hile/micro

Copy-Paste Example

Message handler file:

// src/messages/ping.msg.ts
import { defineMicroMessage } from '@hile/micro'

export default defineMicroMessage(async ({ data, params, invocation }) => {
  return {
    type: 'pong',
    data,
    params,
    requestId: invocation.context.values.requestId,
    timestamp: Date.now(),
  }
})

Microservice boot file:

// src/services/app.boot.ts
import { defineService } from '@hile/core'
import { Application } from '@hile/micro'

export default defineService('micro.app', async (shutdown) => {
  const app = new Application({
    namespace: process.env.MICRO_NAMESPACE ?? 'example.service',
    registry: {
      host: process.env.REGISTRY_HOST ?? '127.0.0.1',
      port: Number(process.env.REGISTRY_PORT ?? 9876),
    },
    advertiseHost: process.env.HILE_ADVERTISE_HOST ?? '127.0.0.1',
  })

  await app.load(new URL('../messages', import.meta.url).pathname)
  const stop = await app.listen(Number(process.env.MICRO_PORT ?? 9877))
  shutdown(stop)
  return app
})

Caller:

import { randomUUID } from 'node:crypto'
import { createExecutionContext } from '@hile/context'

const context = createExecutionContext({ requestId: randomUUID() })
const result = await app.call('example.service', '/ping', { hello: 'world' }, { context })

Typed fixed-path operations

Use defineMicroContract() and createMicroClient() from @hile/micro-contract to share stable JSON schemas and typed remote calls. Implement each operation in its matching message file with defineMicroMessage(operation, handler), then call loadMicroContract(app, contract, messagesDirectory) from @hile/micro to obtain { local, activate, close }.

The binding validates filesystem paths and complete implementation coverage before activation. Explicit local calls are same-service unary calls through the provider executor, not a namespace-based optimization; normal calls still use RPC. Typed remote calls default to zero retries. Native dynamic and streaming APIs remain supported. See packages/micro-contract.md for the full example, schema constraints, and shutdown ordering.

Boundaries

  • Do not use stream() for normal single-result calls.

  • Do not enable retries for a streamed request input. Input streams are consumed once and cannot be replayed safely.

  • Do not rely on message IDs for business idempotency. They are transport IDs.

  • Use defineMicroMessage() for Micro business handlers; reserve generic defineMessage() for transport-neutral loaders.

  • Do not pass zero, fractional, non-finite, or oversized message timeouts. Explicit timeout values must be safe integers from 1 through 2_147_483_647 milliseconds.

  • Appending a secondary response getter to client.request('/x', data)

  • Returning a plain object from a handler called through stream().

  • Retrying a consumed request stream or hiding it inside a replay-unsafe factory.

  • Branching business code on whether a Micro target namespace is local or remote.

  • Using pub/sub as a durable queue.

  • Forgetting to register shutdown(await app.listen(...)).

Verify

  • Micro message files default-export defineMicroMessage(...) and receive invocation.context.
  • Native untyped Micro message files may use [...name].msg.ts; typed Micro Contract implementations remain fixed-path only and reject all parameterized file routes.
  • RPC callers use await app.call(..., { context }).
  • Same-namespace call() and stream() use normal Registry discovery, while streamPeer() keeps its exact-address selection; all three use the normal WebSocket/modem transport path and callers do not branch on locality.
  • Streaming handlers are async generators.
  • Request-stream handlers consume input and callers either pass options.input alongside metadata or pass a stream directly as data.
  • Streamed request calls do not configure nonzero retries.
  • Custom modem timeout values use the documented safe-integer range.
  • File and raw owner conflicts, atomic batch failure, concurrent load rejection, and protocol misdelivery are tested before any handler side effect.
  • Typed fixed-path services validate both actual source and compiled route trees; explicit local and real remote calls test the same provider executor, admission, cancellation, and bounded shutdown.
  • Registry is started before application nodes need discovery.
  • Micro apps use stable namespaces and advertise reachable hosts.

More Context

  • AI.md in this package: full package-local AI guide.
  • Root llms-full.txt: full monorepo AI context.
  • Root references/: source files copied from docs/ai.