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

crocket

v1.0.15

Published

Efficient and simple interprocess communication for unix/windows/macos over tcp or sockets.

Downloads

7,943

Readme

crocket

Node.js CI MIT License Codacy Badge

Minimal node.js cross platform IPC communication library.

  • Communcates over TCP, unix sockets or windows pipe.
  • Works both locally and remotely.
  • Works on Linux, Windows AND macOS.
  • Pluggable event mediator, uses EventEmitter by default. But can be extended with something like qbus for extended functionality.

Installation

npm install crocket

Usage

Host process

var crocket = require("crocket"),
	server = new crocket();

// Start listening, this example communicate by file sockets
server.listen({ "path": "/tmp/crocket-test.sock" }, (e) => { 

	// Fatal errors are supplied as the first parameter to callback
	if(e) throw e; 

	// All is well if we got this far
	console.log('IPC listening on /tmp/crocket-test.sock');

});

// Events are handled by EventEmitter by default ...
server.on('/request/food', function (payload) {
	
	// Respond to the query
	server.emit('/response', 'You asked for food and supplied ' + payload);

});


// React to communication errors
server.on('error', (e) => { console.error('Communication error occurred: ', e); });

Output

> node test-server.js
IPC listening on /tmp/crocket-test.sock

Client process

var crocket = require("crocket"),
	client = new crocket();
	
client.connect({ "path": "/tmp/crocket-test.sock" }, (e) => { 

    // Connection errors are supplied as the first parameter to callback
    if(e) throw e; 

    // Instantly a message to the server
    client.emit('/request/food', 'cash');

});

// Expect a reply on '/response'
client.on('/response', function (what) {

    // Should print 'Server said: You asked for food and supplied cash'
    console.log('Server said: ' + what);

    // Work is done now, no need to keep a connection open
    client.close();

});

Output

> node test-client.js
Server said: You asked for food and supplied cash

Replacing EventEmitter

Host process

var crocket = require("crocket"),

	// Require the alternative event handler
	qbus = require("qbus"),

	// Pass the mediator to the constructor
	server = new crocket(qbus);

// Start listening, this example communicate by file sockets
server.listen({ "path": "/tmp/crocket-test.sock" }, (e) => { 

	// Fatal errors are supplied as the first parameter to callback
	if(e) throw e; 

	// All is well if we got this far
	console.log('IPC listening on /tmp/crocket-test.sock');

});

// Now we're using qbus to handle events
//   Documentation:	https://github.com/unkelpehr/qbus
//   Query tester: 	http://unkelpehr.github.io/qbus/
server.on('/request/:what', function (what, payload) {
	
	// Respond to the query
	server.emit('/response', 'You asked for ' + what + ' and supplied ' + payload);

});

// React to communication errors
server.on('error', (e) => { console.error('Communication error occurred: ', e); });

Output

> node test-server.js
IPC listening on /tmp/crocket-test.sock

Options

All available options for server.listen

Server

{
	"path": "/tmp/node-crocket.sock",
	"host": null,
	"port": null,
	"encoding": "utf8"
}

All available options for client.connect

Client

{
	"path": "/tmp/node-crocket.sock",
	"host": null,
	"port": null,
	"reconnect": -1,
	"timeout": 5000,
	"encoding": "utf8"
}

Path is a file-socket path, normalized by xpipe. As an example, /tmp/my.sock is unchanged on Linux/OS X, while it is transformed to //./pipe/tmp/my.sock on Windows.

Port is specified if you want to use TCP instead of file sockets.

Host Only used in TCP mode. For server, 0.0.0.0 makes crocket listen on any IPv4-interface. :: Is the equivalent for IPv6. For client, you specify the host address.

Reconnect is the number of milliseconds to wait before reviving a broken listener/connection, or -1 to disable automtic revive.

Encoding the encoding used by the underlaying sockets, in most cases this should be left at default.

License

MIT