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 🙏

© 2024 – Pkg Stats / Ryan Hefner

net-ipc

v2.2.0

Published

Simple message based IPC client/server providing bi-directional communication over sockets and TCP. Supports one-way messages, promise-based request-response, survey, broadcast and zlib-stream compression

Downloads

3,873

Readme

net-ipc

A simple message based IPC client/server providing bi-directional communication over sockets and TCP.

Features

  • Promises
  • Unix/Windows sockets for local communication
  • TCP for remote communication
  • Supports multiple clients
  • Supports request-response, survey and broadcast operations
  • Supports secure connections (tls/ssl)
  • Supports http/https proxies
  • Built-in zlib support (requires installing fast-zlib)
  • Built-in messagepack support (requires installing msgpackr)
  • Sexy
  • Fast

Documentation

Examples

Server Examples

Local IPC server for communication between processes in the same machine.

const { Server } = require("net-ipc");
const server = new Server({
    path: "/myapp"
});

server.start().catch(console.error);

TCP server for remote communication over the internet.

const { Server } = require("net-ipc");
const server = new Server({
    port: 4466
});

server.start().catch(console.error);

Secure TCP server with a domain name and an SSL certificate directly exposed to the web.

const { readFileSync } = require("fs");
const { Server } = require("net-ipc");
const server = new Server({
    port: 443,
    tls: true,
    options: {
        cert: readFileSync("/path/to/certificate.pem"),
        key: readFileSync("/path/to/key.pem")
    }
});

server.start().catch(console.error);

Secure TCP server using PSK (pre shared key) instead of an SSL certificate and a domain name. This setup enables secure connections between direct IP addresses.

const USER = "some username";
const KEY = Buffer.from("some password");

const { Server } = require("net-ipc");
const server = new Server({
    port: 4466,
    tls: true,
    options: {
        pskCallback: (socket, identity) => {
            if(identity === USER) { // confirm username
                return KEY; // return password for verification
            }
        },
        ciphers: "PSK", // enable PSK ciphers, they are disabled by default
    }
});

server.start().catch(console.error);

Client Examples

Connecting to a local IPC server.

const { Client } = require("net-ipc");
const client = new Client({
    path: "/myapp"
});

client.connect().catch(console.error);

Connecting to a remote TCP server.

const { Client } = require("net-ipc");
const client = new Client({
    host: "192.168.1.25",
    port: 4466
});

client.connect().catch(console.error);

Connecting to a remote TCP server secured with an SSL certificate and a domain name.

const { Client } = require("net-ipc");
const client = new Client({
    host: "somedomain.com",
    port: 443,
    tls: true
});

client.connect().catch(console.error);

Connecting to a remote TCP server secured with a PSK.

const USER = "username here";
const KEY = "password here";

const { Client } = require("net-ipc");
const client = new Client({
    host: "192.168.1.35",
    port: 4466,
    tls: true,
    options: {
        pskCallback: () => {
            // return the user and the key for verification
            return {
                identity: USER,
                psk: Buffer.from(KEY)
            }
        },
        ciphers: "PSK", // enable PSK ciphers, they are disabled by default
        checkServerIdentity: () => void 0; // bypass SSL certificate verification since we are not using certificates
    }
});

client.connect().catch(console.error);

Connecting to a TCP server behind an SSL proxy (nginx/replit/etc). The server itself does not need to be secure as the proxy does it instead.

const { Client } = require("net-ipc");
const client = new Client({
    host: "somedomain.com",
    port: 443,
    tls: true,
    handshake: true // simulates websocket http handshake
});

client.connect().catch(console.error);

Usage Examples

Request and response example:

// server side
server.on("request", async (req, res, client) => {
    if(req.type === "fetch") {
        const fetched = await someDatabase.fetch(req.data);
        await res(fetched);
    }
});

// client side
const fetched = await client.request({ type: "fetch", data: "someID" });