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

@instantapihq/sdk

v1.0.1

Published

SDK for exposing functions via Instant API

Readme

@instantapihq/sdk

Write functions, get APIs. No servers, no deploy, no boilerplate.

Install

npm install @instantapihq/sdk

Quick Start

import { expose } from '@instantapihq/sdk';

// Define a function
expose('greet', (input) => {
  return { message: `Hello, ${input.name}!` };
});

console.log('Functions running. Press Ctrl+C to exit.');

Run it:

# Terminal 1: Start your functions
node app.js

# Terminal 2: Expose to internet
npx @instantapihq/cli expose greet
# CLI auto-detects and exposes http://localhost:7777/fn/greet

# Terminal 3: Call your API
curl -X POST http://localhost:3001/t/abc123 \
  -d '{"name": "World"}'

How It Works

  1. SDK starts a local Express server (default port: 7777)
  2. Your functions → http://localhost:7777/fn/<name>
  3. CLI creates a public tunnel
  4. Internet → Tunnel → Your function

API

expose(name, handler)

Register a function to be exposed.

expose('functionName', (input) => {
  // Your logic
  return { result: 'whatever' };
});

Handler signature:

  • input: any - The input data from API call
  • returns: any or Promise<any> - The result to return

stop()

Stop the SDK server.

import { stop } from '@instantapi/sdk';

process.on('SIGINT', async () => {
  await stop();
  process.exit(0);
});

Examples

Basic Function

import { expose } from '@instantapihq/sdk';

expose('add', (input) => {
  return { result: input.a + input.b };
});

Async Function

expose('fetchUser', async (input) => {
  const response = await fetch(`https://api.example.com/users/${input.id}`);
  const user = await response.json();
  return { user };
});

Database Query

import { expose } from '@instantapihq/sdk';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

expose('createUser', async (input) => {
  const user = await prisma.user.create({
    data: {
      name: input.name,
      email: input.email,
    },
  });
  return { user };
});

expose('getUser', async (input) => {
  const user = await prisma.user.findUnique({
    where: { id: input.userId },
  });
  return { user };
});

Multiple Functions

import { expose } from '@instantapihq/sdk';

// Data processing
expose('sum', (input) => {
  return { result: input.numbers.reduce((a, b) => a + b, 0) };
});

// Text processing
expose('uppercase', (input) => {
  return { result: input.text.toUpperCase() };
});

// Validation
expose('validate', (input) => {
  const { email } = input;
  const isValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
  return { isValid, email };
});

console.log('3 functions running. Press Ctrl+C to exit.');

TypeScript

Full TypeScript support:

interface AddInput {
  a: number;
  b: number;
}

interface AddOutput {
  result: number;
}

expose('add', (input: AddInput): AddOutput => {
  return { result: input.a + input.b };
});

Error Handling

Errors are automatically caught and returned as JSON:

expose('divide', (input) => {
  if (input.b === 0) {
    throw new Error('Cannot divide by zero');
  }
  return { result: input.a / input.b };
});

// Error response:
// { "error": "Cannot divide by zero", "stack": "..." }

Authentication

Function mode requires an API key:

# 1. Sign up at your Instant API instance
# 2. Generate API key
# 3. Set it:
export INSTANT_API_KEY=ik_your_key_here

# 4. Expose functions
npx @instantapihq/cli expose myFunction

Metadata File

The SDK creates .instant-api-sdk.json for CLI detection:

{
  "port": 7777,
  "functions": ["greet", "calculate"],
  "pid": 12345
}

This file is automatically cleaned up when your app exits.

Health Check

curl http://localhost:7777/health

# Response:
# {
#   "status": "ok",
#   "functions": ["greet", "calculate"],
#   "port": 7777
# }

What Works

  • Sync and async functions
  • TypeScript support
  • Error handling
  • Multiple functions
  • JSON input/output
  • Auto port selection (7777-7781)

Great For

  • Quick prototypes
  • Webhook handlers
  • AI/ML inference APIs
  • Microservice testing
  • Database operations
  • Data processing functions

Requirements

  • Node.js 18+
  • @instantapihq/cli for exposing functions
  • Instant API backend (local or production)

License

See FSL-1.1-MIT for full details.