# isnode-mod-router

> ISNode Router Module

Latest version **0.1.6** (published 2020-01-14) · 0 weekly downloads

## Install

```sh
npm install isnode-mod-router
pnpm add isnode-mod-router
yarn add isnode-mod-router
bun add isnode-mod-router
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2020-01-14 |
| First published | 2018-06-14 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 60.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Darren Smith |
| Maintainers | lifesanexperience |

## Links

- npm: https://www.npmjs.com/package/isnode-mod-router
- Repository: https://github.com/Industryswarm/isnode-mod-router
- Homepage: https://github.com/Industryswarm/isnode-mod-router#readme
- Issues: https://github.com/Industryswarm/isnode-mod-router/issues
- npm.io page: https://npm.io/package/isnode-mod-router

## Recent versions

- 0.1.6 (latest) — 2020-01-14
- 0.1.5 — 2020-01-14
- 0.1.4 — 2020-01-12
- 0.1.2 — 2019-07-21
- 0.1.1 — 2019-05-15
- 0.1.0 — 2019-05-15
- 0.0.8 — 2019-05-04
- 0.0.5 — 2019-04-04
- 0.0.1 — 2018-06-14

## README

# ISNode Router Module

###### <br/>

## Introduction

*This is just a module for the ISNode Framework. To learn how to use the framework, we strongly suggest obtaining a copy of the [Hello World](https://github.com/Industryswarm/hello-world-service) example.*

The router module is responsible for creating, managing and utilizing routers. Routers are defined within the system configuration file and are responsible for passing requests from interfaces through to service controllers.

<br/><br/>


## System Configuration

Below is an example configuration for the router module within the system configuration file (config.json). It defines a single router instance that routes messages from all interfaces to all services. You can also define individual interfaces and services by name within the array instead of the "select all" (\*) symbol. This module also supports the definition of multiple routers - and thus makes for a very configurable framework.

```javascript
  "router": {
    "instances": {
      "RouterOne": {
        "interfaces": ["*"],
        "services": ["*"]
      }
    }
  }
```


<br/><br/>

## Methods


### count()

Synchronous Function. Returns a count of the number of routers that have been instantiated

**Input Parameters:** 

N/A

**Returns:** (Integer) A count of the number of instantiated routers

#### Example

```javascript
	console.log(isnode.module("router").count()); // Prints "2" to the console if 2 routers have been instantiated
```

<br/><br/>

### get(name)

Synchronous Function. Returns a router based on its name

**Input Parameters:** 

1. **name** - (Object) Name of the router

**Returns:** The router object

#### Example

```javascript
	var RouterOne = isnode.module("router").get("RouterOne");
```

<br/><br/>

### router.incoming(message)

Event-Driven Function. Accepts an incoming message from an interface and routes it to the relevent service controller. Also opens a listener for a response event and routes it back to the interface when received.

**Input Parameters:** 

1. **message** - (Object) Message Object

**Returns:** N/A

#### Example

```javascript
	var message = {
		"type": "http",
		"interface": "http",
		"msgId": "1234",
		"state": "incoming",
		"directional": "simplex",
		"request": {
			"path": "/",
			"host": "localhost",
			"port": 80,
			"query": "name=john@age=21",
			"headers": {},
			"params": {},
			"cookies": {},
			"ip": "127.0.0.11",
			"verb": "GET",
			"secure": false,
			"body": "",
		}
	}

	var RouterOne = isnode.module("router").get("RouterOne");
	RouterOne.incoming(message);
```

<br/><br/>

### router.route(hostname, url)

Synchronous Function. Returns a route object that references service+controller, based on a hostname and url (path)

**Input Parameters:** 

1. **hostname** - (String) Hostname
1. **url** - (String) URL Path

**Returns:** N/A

#### Example

```javascript
	var route = RouterOne.route("localhost", "/test");
```

<br/><br/>

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