New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

sproc

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sproc

shared process

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

sproc

This module is useful when you want to spawn a single daemon and be able to connect to it from other processes.

workflow:

  • attempt to connect to daemon
  • if connection fails, spawn daemon (return to first step)
  • upon connection, callback with a stream

Install

npm install sproc

Use

daemon.js


// echo daemon

var clients = 0;

module.exports = function(options, stream) {
  clients++;

  stream.write(clients + ' clients');
  stream.on('end', function() {
    clients--;
    if (clients > 0) {
      stream.write(clients + ' clients');
    } else {
      process.exit();
    }
  });

  stream.pipe(stream, { end: false });
};

main.js


var sproc = require('sproc');

sproc({
  script: './daemon',
  port: 4499,
}, function(proc) {
  proc.stream.write('hello');
  stream.on('data', console.log); // outputs hello
});

options

  • port - port to use for listening/connecting (default: 4499)
  • keepProcessReference - do not detatch from the daemon (default: false)
  • log - a function (optional)

License

MIT

Keywords

shared

FAQs

Package last updated on 22 Feb 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts