# micro-tcp

> Easy, Fast, Lightweight Asynchronous TCP microservices

Latest version **0.3.0** (published 2018-02-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install micro-tcp
pnpm add micro-tcp
yarn add micro-tcp
bun add micro-tcp
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-02-15 |
| First published | 2017-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adam Patai |
| Maintainers | pataiadam |
| Keywords | micro, microservice, tcp, fast, serverless, API |

## Links

- npm: https://www.npmjs.com/package/micro-tcp
- Repository: https://github.com/pataiadam/micro-tcp
- Homepage: https://github.com/pataiadam/micro-tcp#readme
- Issues: https://github.com/pataiadam/micro-tcp/issues
- npm.io page: https://npm.io/package/micro-tcp

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-02-15
- 0.2.0 — 2017-10-08
- 0.1.0 — 2017-10-03

## README

# micro-tcp
Easy, Fast, Lightweight Asynchronous TCP microservices

## Installation

```
npm install micro-tcp
```

## Usage

### Server

```
const Micro = require('micro-tcp');
const micro = new Micro();

micro.add('sayHi', async (name, res) => res('Hi ' + name + '!'));

micro.listen({ port: 3000 });
```

### Client

```
const Micro = require('micro-tcp');
const micro = new Micro();

micro.createClient({ port: 3000 }, async client => {
  const result = await client.sayHi('Alice');
  console.log(result) // 'Hi Alice!'
});
```

## Example

### Server

```
const Micro = require('./lib');
const micro = new Micro();

const posts = [];

micro.add('post.get', async (index) => posts[index]);
micro.add('post.list', async (params) => {
  const skip = params.skip || 0;
  const limit = params.limit || 10;
  return posts.slice(skip, skip+limit)
});
micro.add('post.create', async (post) => {
  posts.push(post);
  return post;
});

micro.listen({ port: 3000 }, () => console.log('Listening on 3000...'));
```

### Client

```
const Micro = require('./lib');
const micro = new Micro();

micro.createClient({ port: 3000 }, async client => {
  console.log('CONNECTED');
  await client.post.create({title: 'First post'});
  await client.post.create({title: 'Second post'});
  await client.post.create({title: 'Third post'});

  const post = await client.post.get(0);
  console.log(post);

  const posts = await client.post.list({skip: 1, limit: 2})
  console.log(posts);
});

```

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