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

alien-rpc

v0.4.1

Published

Full-stack library and command-line tool for alien-rpc

Readme

alien-rpc

A type-safe RPC library for TypeScript that bridges the gap between your server and client with minimal boilerplate and maximum performance.

Key Features

  • Type-safe by default: Share types between server and client without manual effort.
  • Automatic Code Generation: CLI scans your routes and generates client-side calling code and server-side manifests.
  • Validation: Integrated with TypeBox for robust runtime validation using TypeScript types.
  • Middleware Support: Powered by alien-middleware for powerful, type-safe request context propagation.
  • Websocket Support: First-class support for websockets via crossws.
  • Flexible Formats: Supports JSON, JSON-Seq (for pagination/streaming), and raw Responses.

Installation

npm install alien-rpc

Quick Start

1. Define a route

Create a file for your routes (e.g., server/api/hello.ts):

import { route } from 'alien-rpc/service'

// One path parameter
export const hello = route('/hello/:name').get(async (name, {}, ctx) => {
  return { message: `Hello, ${name}!` }
})

// Multiple path parameters
export const multiple = route('/user/:id/post/:postId').get(
  async ([id, postId], {}, ctx) => {
    return { id, postId }
  }
)

// No path parameters
export const noParams = route('/status').get(async ({}, ctx) => {
  return { ok: true }
})

2. Generate client & server manifests

Run the alien-rpc CLI to scan your routes and generate the necessary manifests:

npx alien-rpc './server/api/**/*.ts' --clientOutFile ./client/api.ts --serverOutFile ./server/api.ts

[!TIP] See CLI and Configuration for more details.

3. Use the client

In your client-side code:

import { defineClient } from 'alien-rpc/client'
import routes from './api.ts'

const client = defineClient(routes, {
  prefixUrl: '/api',
})

// Parameters can be passed directly if there's only one path param
const result = await client.hello('World')
console.log(result.message) // "Hello, World!"

4. Setup the server

Use the generated server manifest with any Hattip-compatible adapter. For example, using @hattip/adapter-node:

import { createServer } from '@hattip/adapter-node'
import { compileRoutes } from 'alien-rpc/service'
import { chain } from 'alien-rpc/middleware'
import routes from './server/api.ts'

const handler = chain(
  compileRoutes(routes, {
    prefix: '/api/',
  })
)

createServer(handler).listen(3000)

Core Concepts

Middlewares and Context

Use route.use() to create factories with shared middlewares. Middlewares can provide context (like a database or user session) to your handlers.

import { chain } from 'alien-rpc/middleware'
import { route } from 'alien-rpc/service'

const withUser = chain(async ctx => {
  const user = await getUser(ctx.request)
  return { user }
})

const userRoute = route.use(withUser)

export const getProfile = userRoute('/me').get(async (_, ctx) => {
  return ctx.user // Type-safe access to user!
})

[!TIP] See Middlewares and Context for more details.

Validation Constraints

Use TypeScript types to define validation rules. The generator automatically converts these to TypeBox schemas.

import type { t } from 'alien-rpc/service'

export const updateBio = route('/bio').post(
  async ({ bio }: { bio: string & t.MaxLength<140> }) => {
    // bio is guaranteed to be <= 140 chars
  }
)

Path Parameter Coercion

Path parameters are automatically coerced based on the types defined in your handler's signature. Supported types include string and number.

export const getById = route('/item/:id').get(async (id: number) => {
  // id is guaranteed to be a number!
})

[!TIP] See Validation and Coercion for more details.

Websockets

Define websocket routes that share the same connection:

export const chat = route.ws(ctx => {
  ctx.on('message', msg => {
    ctx.send({ echo: msg })
  })
})

[!TIP] See Websockets for more details.

Pagination and Streaming

Support efficient data transfer for lists and large datasets.

export const listItems = route('/items').get(async function* ({ offset = 0 }) {
  const items = await db.items.findMany({ skip: offset, take: 10 })
  for (const item of items) yield item
  return paginate(this, {
    next: { offset: offset + 10 },
  })
})

[!TIP] See Pagination and Streaming for more details.

Examples

Check out the examples directory for minimal, ready-to-run projects using different stacks:

  • Astro: Integration with Astro's server-side routes and client-side components.
  • Vite + Node.js: A full-stack setup with a Node.js backend proxied through Vite.
  • Vite + Cloudflare Workers: Deploying to Cloudflare Workers using Vite and @cloudflare/vite-plugin.

Configuration

For larger projects, use an alien-rpc.config.ts file:

import { defineConfig } from 'alien-rpc/config'

export default defineConfig({
  include: ['./server/api/**/*.ts'],
  outDir: './src/generated',
  clientOutFile: 'client.ts',
  serverOutFile: 'server.ts',
})

[!TIP] See CLI and Configuration for more details.

License

MIT