<commit_before># flic [![Build Status](https://travis-ci.org/nkcmr/flic.png?branch=master)](https://travis-ci.org/nkcmr/flic) [![npm version](https://img.shields.io/npm/v/flic.svg?style=flat-square)](https://www.npmjs.com/package/flic)
easy inter-process communication via tcp.



# install


```bash
npm install --save flic
```

# usage
flic's main purpose is to faciliate shuffling and passing of arbitrary data across various processes or networks.

being able to split up your application into different processes and even machines can vastly improve reliability and scalability, especially in an environment like node.js, where if your only process fails, your whole app is down.

```javascript
var flic = require('flic')

// bridges can be in any process, and nodes can be in any process
var bridge = flic.createBridge()

var node1 = flic.createNode('node1', function (err) {
  if (err) {
    return handle_error(err)
  }

  // successfully connected to bridge
  console.log('node1 online!');
});

node1.on('event', function (param1, callback) {
  // do awesomeness
  console.log(param1) // -> 'flic_is_easy'

  // send a callback fig.1
  callback(null, 'ilovenodejs')
})
```
somewhere else, in another process far far away!

```javascript
// make anonymous nodes by not giving it a name
// anonymous nodes:
// cannot be told (node.tell) anything
// can tell other nodes
// can receive shouts
// helps avoid duplicate node names

var anonymous_node = flic.createNode(function (err) {
  if (err) {
    return handle_error(err)
  }
  console.log('somenode online!')
})

anonymous_node.tell('node1:event', 'flic_is_easy', function (err, param2) {
  if (err) {
    return handle_error(err)
  }
  console.log(param2) // -> 'ilovenodejs'
})

```

# api

- **flic**
	- **flic.createNode([config])**
	- **flic.createBridge([config])**
	- **Class: flic.Bridge**
		- **bridge.close([data][,...])**
	- **Class: flic.Node**
		- **node.tell(whowhat, [args][,...], [callback])**
		- **node.shout(event, [args][,...])**
		- **node.leave([force])**

### flic
the `flic` module can be accessed by using `require('flic')`

### flic.createNode([config])
creates a new node. `config` is an object with the following available properties:

- `id` string - optional.
- `port` number - optional.
- `connect_callback` function - optional.
- `max_connection_attempts` number - optional.
- `timeout` number - optional.

### flic.createBridge([config])
creates a new bridge. `config` is an object with the following available properties:

- `port` number - optional.

### Class: flic.Bridge
the bridge is the middle-man between nodes that helps pass messages along.

### bridge.close([data][,...])
close the underlying server and optionally send any parting data.

```javascript
var bridge = flic.createBridge()
// ... later ...

// send an object to all nodes before leaving
bridge.close({ reason: 'im tired' })
```<commit_msg>update readme links for the api<commit_after># flic [![Build Status](https://travis-ci.org/nkcmr/flic.png?branch=master)](https://travis-ci.org/nkcmr/flic) [![npm version](https://img.shields.io/npm/v/flic.svg?style=flat-square)](https://www.npmjs.com/package/flic)
easy inter-process communication via tcp.



# install


```bash
npm install --save flic
```

# usage
flic's main purpose is to faciliate shuffling and passing of arbitrary data across various processes or networks.

being able to split up your application into different processes and even machines can vastly improve reliability and scalability, especially in an environment like node.js, where if your only process fails, your whole app is down.

```javascript
var flic = require('flic')

// bridges can be in any process, and nodes can be in any process
var bridge = flic.createBridge()

var node1 = flic.createNode('node1', function (err) {
  if (err) {
    return handle_error(err)
  }

  // successfully connected to bridge
  console.log('node1 online!');
});

node1.on('event', function (param1, callback) {
  // do awesomeness
  console.log(param1) // -> 'flic_is_easy'

  // send a callback fig.1
  callback(null, 'ilovenodejs')
})
```
somewhere else, in another process far far away!

```javascript
// make anonymous nodes by not giving it a name
// anonymous nodes:
// cannot be told (node.tell) anything
// can tell other nodes
// can receive shouts
// helps avoid duplicate node names

var anonymous_node = flic.createNode(function (err) {
  if (err) {
    return handle_error(err)
  }
  console.log('somenode online!')
})

anonymous_node.tell('node1:event', 'flic_is_easy', function (err, param2) {
  if (err) {
    return handle_error(err)
  }
  console.log(param2) // -> 'ilovenodejs'
})

```

# api

- **[flic](#flic)**
	- **[flic.createNode([config])](#fliccreatenodeconfig)**
	- **[flic.createBridge([config])](#fliccreatebridgeconfig)**
	- **[Class: flic.Bridge](#class-flicbridge)**
		- **[bridge.close([data][,...])](#bridgeclosedata)**
	- **[Class: flic.Node](#class-flicnode)**
		- **[node.tell(whowhat, [args][,...], [callback])](#nodetellwhowhat-args-callback)**
		- **[node.shout(event, [args][,...])](#nodeshoutevent-args)**
		- **[node.leave([force])](#nodeleaveforce)**

### flic
the `flic` module can be accessed by using `require('flic')`

### flic.createNode([config])
creates a new node. `config` is an object with the following available properties:

- `id` string - optional.
- `port` number - optional.
- `connect_callback` function - optional.
- `max_connection_attempts` number - optional.
- `timeout` number - optional.

### flic.createBridge([config])
creates a new bridge. `config` is an object with the following available properties:

- `port` number - optional.

### Class: flic.Bridge
the bridge is the middle-man between nodes that helps pass messages along.

### bridge.close([data][,...])
close the underlying server and optionally send any parting data.

```javascript
var bridge = flic.createBridge()
// ... later ...

// send an object to all nodes before leaving
bridge.close({ reason: 'im tired' })
```
{'fraction_non_alphanumeric': 0.15555555555555556, 'fraction_numerical': 0.003316749585406302, 'mean_word_length': 4.14151747655584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5228300', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1854, 'n_words': 589}