Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/oresoftware/json-stdio
- Owner: ORESoftware
- License: mit
- Created: 2017-11-06T18:52:12.000Z (about 7 years ago)
- Default Branch: dev
- Last Pushed: 2019-10-22T00:03:19.000Z (about 5 years ago)
- Last Synced: 2024-04-26T18:23:07.291Z (8 months ago)
- Topics: inter-process-communication, ipc, json, nodejs, stderr, stdout, text-streams, unix, unix-philosophy
- Language: JavaScript
- Size: 38.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
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 processconst 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'}
});```