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

ndk-rpc-engine

v1.0.5

Published

Lightweight RPC engine for Node.js with client and server support

Readme

NDK RPC Engine

🚀 A lightweight, fast, and easy-to-use RPC (Remote Procedure Call) engine for Node.js with built-in client and server support.

Features

  • Simple Setup - Get started with just a few lines of code
  • Client & Server - Built-in client and server components
  • Type Flexible - Support for various parameter types (arrays, objects, primitives)
  • Error Handling - Comprehensive error handling and validation
  • Express Integration - Built on top of Express.js
  • CORS Support - Cross-origin requests supported out of the box
  • Lightweight - Minimal dependencies and fast performance

Installation

npm install ndk-rpc-engine

Quick Start

Server Setup

import ndk_rpc_server from "ndk-rpc-engine/server";

// Create server instance
const server = new ndk_rpc_server({ port: 4000 });

// Define your functions
const add = ({ a, b }) => a + b;
const subtract = ({ a, b }) => a - b;
const hello = () => "Hello, World!";

// Register functions
await server.register_functions([
  {
    function_name: "add",
    function_block: add,
  },
  {
    function_name: "subtract",
    function_block: subtract,
  },
  {
    function_name: "hello",
    function_block: hello,
  }
]);

// Start the server
await server.start();
console.log("🚀 NDK RPC Server is running!");

Client Setup

import { Client } from "ndk-rpc-engine/client";

// Create client instance
const client = new Client({
    server_port: 4000 
});

// Call remote functions
const response = await client.request({
    method: "add",
    params: { a: 5, b: 3 }
});

console.log(response.data.result); // Output: 8

API Reference

Server API

new ndk_rpc_server(options)

Creates a new RPC server instance.

Parameters:

  • options.port (number, optional) - Server port (default: 3000)

server.register_functions(functions)

Registers an array of functions to be callable via RPC.

Parameters:

  • functions (Array) - Array of function objects

Function Object Structure:

{
  function_name: "string", // Unique function name
  function_block: function // The actual function to execute
}

Example:

await server.register_functions([
  {
    function_name: "calculate",
    function_block: ({ operation, a, b }) => {
      if (operation === "add") return a + b;
      if (operation === "multiply") return a * b;
      throw new Error("Unknown operation");
    }
  }
]);

server.start()

Starts the RPC server.

Client API

new Client(options)

Creates a new RPC client instance.

Parameters:

  • options.server_port (number, optional) - Server port to connect to (default: 3000)

client.request(options)

Makes an RPC call to the server.

Parameters:

  • options.method (string) - Name of the remote function to call
  • options.params (any, optional) - Parameters to pass to the function

Returns:

  • Promise resolving to server response

Response Format:

{
  statusCode: 200,
  message: "Method executed successfully",
  data: {
    method_name: "function_name",
    result: "function_result"
  }
}

Examples

Example 1: Basic Math Operations

Server:

import ndk_rpc_server from "ndk-rpc-engine/server";

const server = new ndk_rpc_server({ port: 4000 });

const mathOperations = {
  add: ({ a, b }) => a + b,
  subtract: ({ a, b }) => a - b,
  multiply: ({ a, b }) => a * b,
  divide: ({ a, b }) => {
    if (b === 0) throw new Error("Division by zero!");
    return a / b;
  }
};

await server.register_functions([
  { function_name: "add", function_block: mathOperations.add },
  { function_name: "subtract", function_block: mathOperations.subtract },
  { function_name: "multiply", function_block: mathOperations.multiply },
  { function_name: "divide", function_block: mathOperations.divide }
]);

await server.start();

Client:

import { Client } from "ndk-rpc-engine/client";

const client = new Client({ server_port: 4000 });

// Addition
const addResult = await client.request({
  method: "add",
  params: { a: 10, b: 5 }
});
console.log("10 + 5 =", addResult.data.result); // 15

// Division with error handling
try {
  const divResult = await client.request({
    method: "divide",
    params: { a: 10, b: 0 }
  });
} catch (error) {
  console.error("Error:", error.message);
}

Example 2: Array Parameters

// Server function
const processArray = (numbers) => {
  return numbers.reduce((sum, num) => sum + num, 0);
};

await server.register_functions([
  { function_name: "sum_array", function_block: processArray }
]);

// Client call
const result = await client.request({
  method: "sum_array",
  params: [1, 2, 3, 4, 5]
});
console.log("Sum:", result.data.result); // 15

Example 3: No Parameters

// Server function
const getServerTime = () => new Date().toISOString();

await server.register_functions([
  { function_name: "server_time", function_block: getServerTime }
]);

// Client call
const result = await client.request({
  method: "server_time"
  // No params needed
});
console.log("Server time:", result.data.result);

Error Handling

The engine provides comprehensive error handling:

try {
  const response = await client.request({
    method: "nonexistent_function",
    params: { a: 1, b: 2 }
  });
} catch (error) {
  console.error("RPC Error:", error.message);
  // Handle different error types
  if (error.message.includes("not found")) {
    console.log("Function doesn't exist on server");
  }
}

Server Endpoints

When you start the server, these endpoints become available:

  • GET http://localhost:{port}/ - Health check
  • POST http://localhost:{port}/api/v1/rpc/run-rpc-method - Execute RPC methods

Configuration

CORS

The server comes with CORS enabled by default for all origins. Perfect for web applications.

Express Middleware

Built on Express.js, so you can extend it with additional middleware if needed.

License

MIT © Navnath Kadam

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Support

If you encounter any issues or have questions, please open an issue on GitHub.


Made with ❤️ by Navnath Kadam

A lightweight RPC (Remote Procedure Call) engine built from scratch in Node.js. It allows you to easily register functions on the server and call them remotely from a client using simple JSON-based requests.


🚀 About This Project

NDK-RPC-Engine provides a minimal and extensible way to:

  • Register server-side functions globally.
  • Call those functions from clients over HTTP.
  • Get structured JSON responses with status codes and results.

This makes it ideal for building microservices, distributed systems, or simple client-server communication without heavy dependencies.


📦 Installation

Clone the repository and install dependencies:

git clone https://github.com/yourusername/ndk-rpc-engine.git
cd ndk-rpc-engine
npm install

🖥️ Usage

1. Server Setup

You can register multiple functions and expose them via the RPC server.

import ndk_rpc_server from "../server/index.mjs";

let server = new ndk_rpc_server({ port: 4000 });

const add = ({a, b}) => a + b;
const subtract = ({a, b}) => a - b;
const hello = () => "Hello, World!";

const isRegistered = await server.register_functions([
  {
    function_name: "add",
    function_block: add,
  },
  {
    function_name: "subtract",
    function_block: subtract,
  },
  {
    function_name: "hello",
    function_block: hello,
  }
]);

await server.start();

Server Console Output:

Global Registered function: [object Object]
Registered functions: [
  { function_name: 'add', function_block: [Function: add] },
  { function_name: 'subtract', function_block: [Function: subtract] },
  { function_name: 'hello', function_block: [Function: hello] }
]
NDK-RPC-Engine started at port: http://localhost:4000

2. Client Usage

Clients can call any registered function on the server.

import { Client } from "../index.mjs";

const client = new Client({
    server_port: 4000
});

const response = await client.request({
     method : "add",
     params: { a: 5 , b: 4 }
});

console.log("Response from server to Client : " , response);

Client Console Output:

Response from server to Client :  {
  message: 'Method executed successfully',
  method_name: 'add',
  result: 9
}

🛠️ Features

  • Simple function registration (register_functions).
  • JSON-based request/response.
  • Built-in error handling (e.g., method not found, invalid params).
  • Supports multiple clients.

📌 Example Methods

  • add({a, b}) → returns sum.
  • subtract({a, b}) → returns difference.
  • hello() → returns greeting string.

📖 Roadmap

  • [ ] Add WebSocket support for bi-directional communication.
  • [ ] Support authentication (JWT/OAuth).
  • [ ] Function namespaces for modularity.
  • [ ] Middleware hooks (logging, validation, etc.).

🤝 Contributing

Feel free to fork, open issues, and submit PRs.


📜 License

MIT License © 2025 Ndk