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

@crussell52/socket-ipc

v0.4.1

Published

An event-driven IPC implementation using unix file sockets.

Downloads

139

Readme

About

An event-driven IPC implementation for NodeJS using unix file sockets

Docs | Source | Releases | NPM

Table of Contents

About (you are here)

Usage

Advanced Usage

API

Quick Start

Want to get up and running quickly? This is for you.

Install

npm install --save @crussell52/socket-ipc

A Simple Example

Client:

const {Client} = require('@crussell52/socket-ipc');
const client = new Client({socketFile: '/tmp/myApp.sock'});

// Say hello as soon as we connect to the server with a simple message
// that give it our name.
client.on('connect', () => client.send('hello', {name: 'crussell52'}));

// Connect. It will auto-retry if the connection fails and auto-reconnect if the connection drops.
client.connect();

Server:

const {Server} = require('@crussell52/socket-ipc');
const server = new Server({socketFile: '/tmp/myApp.sock'});

// Listen for errors so they don't bubble up and kill the app.
server.on('error', err => console.error('IPC Server Error!', err));

// Log all messages. Topics are completely up to the sender!
server.on('message', (message, topic) => console.log(topic, message));

// Say hello back to anybody that sends a message with the "hello" topic. 
server.on('message.hello', (message, clientId) => server.send('hello', `Hello, ${message.name}!`, clientId));

// Start listening for connections.
server.listen();

// Always clean up when you are ready to shut down your app to clean up socket files. If the app
// closes unexpectedly, the server will try to "reclaim" the socket file on the next start.
function shutdown() {
    server.close();
}

More Examples

Check out the /examples directory in the source for more code samples. (Make sure you set the SOCKET_FILE constant at the top of the example files before you run them!)

Limitations

Let's get this out of the way early...

Requires:

  • NodeJS >= 8.x LTS (might work with perfectly fine with some older versions -- but not tested)

Transport Support:

  • Unix socket files (might work with windows socket files too -- but not tested)

Unsupported Features:

  • TCP Sockets
  • UDP Sockets
  • Windows socket files (well maybe it does, I haven't tried )
  • Native client-to-client communication (although you could implement it!)

Love the project, but you need it to do something it doesn't? Open up a feature request!

Alternate solutions

node-ipc ZeroMQ

Why this one?

When I needed to solve this problem, most of what I found was tied to some extra external dependency or platform (electron, redis, etc). The node-ipc lib caught my eye for a time, but I wasn't in love with the interface and it was published under a non-standard (and sometimes considered "satirical") license.

So this package was born. Here are the goals of this project:

  • Bidirectional communication over Unix sockets (maybe other transports, in the future)
  • Simple interface for sending messages:
    • From the server to a specific client
    • From the server to all clients (broadcast)
    • From any client to the server
  • Minimize dependencies (So far, 0!).
  • Event driven (using native NodeJS EventEmitter)
  • Ability to listen for all messages or to narrow in on specific topics.
  • Built-in client resiliency (automatic reconnection, automatic connection retry)
  • Extensible design:
    • Pluggable
    • Stable API
    • Thorough docs to make wrapping or extending easy
    • Leave domain details to the domain experts