0.1.112 • Published 5 years ago

json-stdio v0.1.112

Weekly downloads
11
License
MIT
Repository
github
Last release
5 years ago

json-stdio

Version

This library allows two Node.js processes to easily communicate via stdout/stderr/stdin.

Usage / Getting Started

Importing

import stdio = require('json-stdio');    //   TypeScript
import * as stdio from 'json-stdio';     //   ESNext / ES-Whatever
const stdio = require('json-stdio');     //   Old-Skool

Writing to stdout/stderr (sender process):

// log a file path, which can be received by another process

const stdio = require('json-stdio');
const filePath = '/foo/bar';
stdio.log({fp: filePath});
stdio.logerr({fp: filePath});

Parsing a stream (receiver process)

const stdio = require('json-stdio');
const cp = require('child_process');

const k = cp.spawn('bash');

const parser = stdio.createParser();
const stdEventName = stdio.stdEventName;  // '@json-stdio-event'

k.stdout.pipe(parser).on(stdEventName, obj => {
  
    // obj is an object like so:
    // {fp: '/foo/bar'}
});