Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oresoftware/json-stdio

Write standardized JSON to stdio streams. Parse a standardized stdio stream.
https://github.com/oresoftware/json-stdio

inter-process-communication ipc json nodejs stderr stdout text-streams unix unix-philosophy

Last synced: 8 days ago
JSON representation

Write standardized JSON to stdio streams. Parse a standardized stdio stream.

Awesome Lists containing this project

README

        

# json-stdio


[![Version](https://img.shields.io/npm/v/json-stdio.svg?colorB=green)](https://www.npmjs.com/package/json-stdio)


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

### Usage / Getting Started

## Importing

```js
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):

```javascript
// 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)

```javascript
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'}
});

```