# @profiprog/socket-link

> Allow simply setup socket communication between processes

Latest version **1.0.0** (published 2020-07-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install @profiprog/socket-link
pnpm add @profiprog/socket-link
yarn add @profiprog/socket-link
bun add @profiprog/socket-link
```

Provides the command `socket-link`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-07-13 |
| First published | 2020-07-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 41.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | https://github.com/profiprog |
| Maintainers | profiprog |
| Keywords | socket, io |

## Links

- npm: https://www.npmjs.com/package/@profiprog/socket-link
- Repository: https://github.com/profiprog/socket-link
- Homepage: https://github.com/profiprog/socket-link#readme
- Issues: https://github.com/profiprog/socket-link/issues
- npm.io page: https://npm.io/package/@profiprog/socket-link

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2020-07-13

## README

# socket-link
Allow simply setup socket communication between processes


## Usage
```npm istall --save @profiprog/socket-link```

### Server side
```js
const { startService, ErrorResponse } import('@profiprog/socket-link');
const socketPath = './myapp.sock';

function isValid(name) { return name[0].toUpperCase(0) === name[0]; }

startService(socketPath, ({ id, body }) => {
    console.log(`Request(${id}):`, body);
    if (isValid(body.name)) return { greeting: 'Hello ' + body.name };
    else throw new ErrorResponse('Invalid name', { name });
});
```

### Clinet side
```js
const { requestService } import('@profiprog/socket-link');
const socketPath = './myapp.sock';

// one request per connection
requestService(socketPath, { body: { name: 'Socket' } })
    .then(({ greeting }) => console.log(greeting))
    .catch(e => console.error(e));

// multiple requests per connection
requestService(socketPath, async call => {
    try {
        let { greeting: greetingForAdam } = await call({name: 'Adam'});
        let { greeting: greetingForEva } = await call({name: 'Eva'});
        console.log({greetingForAdam, greetingForEva});
    }
    catch (error) { console.error(error); }
});

// start interactive shell
const readline = require('readline');
requestService(socketPath, readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    prompt: '> ',
}));
```

---
_Source: https://npm.io/package/@profiprog/socket-link · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
