Socket
Socket
Sign inDemoInstall

conn-wrapper

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    conn-wrapper

A wrapper for connections which only allows passing string.


Version published
Maintainers
1
Created

Readme

Source

conn-wrapper

A simple wrapper for connections which only allows passing string.

NPM version Build Status Dependency Status Coverage percentage

Usecase

There are a lots of times communication through connections and processes require dynamic Event Emitter rather than only listening on message event. This module allows dev to create events dynamicly through those connections.

Installation

  npm install --save conn-wrapper

Usage

Vanila

const cp = require('child_process');

const child = cp.fork(path.join('./child.js'));

child.on('message', function(message) {
  m = JSON.parse(message);

  if (m.event === 'event1') {
    // Do something
  } else if (m.event === 'event2') {
    // Do something
  } else if (m.event === 'event2') {
    ...
  }
  ...
})

With conn-wrapper

const ConnWrapper = require('conn-wrapper');
const cp = require('child_process');

const child = cp.fork(path.join('./child.js'));
const wrapper = ConnWrapper(child);

// Send event
wrapper.send('event', payload)

// Listen for an event
wrapper.on('event1', function(payload) {
  // Do something
});

To achieve this, the message sent by conn.send() must be a json or json format string. All other type will be ignored.

The message has 2 fields: event (name of the event to be listened on) and body (optinal, main content).

Getting To Know Yeoman

Yeoman has a heart of gold. He's a person with feelings and opinions, but he's very easy to work with. If you think he's too opinionated, he can be easily convinced. Feel free to learn more about him.

Created with

Yeoman and Generator-simple-package

License

MIT © nghiattran

FAQs

Last updated on 17 Jul 2017

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc