# service-host

> JS service host

Latest version **0.2.0** (published 2015-03-29) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install service-host
pnpm add service-host
yarn add service-host
bun add service-host
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2015-03-29 |
| First published | 2015-03-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Mark Finger |
| Maintainers | markfinger |

## Links

- npm: https://www.npmjs.com/package/service-host
- Repository: https://github.com/markfinger/service-host
- Issues: https://github.com/markfinger/service-host/issues
- npm.io page: https://npm.io/package/service-host

## Dependencies (6)

- [debug](https://npm.io/package/debug.md) ^2.1.3
- [yargs](https://npm.io/package/yargs.md) ^3.5.4
- [lodash](https://npm.io/package/lodash.md) ^3.5.0
- [express](https://npm.io/package/express.md) ^4.11.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.12.0
- [absolute-path](https://npm.io/package/absolute-path.md) 0.0.0

## Recent versions

- 0.2.0 (latest) — 2015-03-29
- 0.1.1 — 2015-03-22
- 0.1.0 — 2015-03-22

## README

service-host
============

[![Build Status](https://travis-ci.org/markfinger/service-host.svg?branch=master)](https://travis-ci.org/markfinger/service-host)


Installation
------------

```
npm install service-host
```


CLI usage
---------

```bash
# Start up a service host
node bin/start.js --config path/to/config.js
```

Config files should export an object.


Programmatic usage
------------------

```javascript
var Host = require('service-host');

var host = new Host({
  debug: true,
  port: 9000,
});

host.addService({
  name: 'foo',
  handler: function(data, done) {
    // ...
    if (someError) {
      done(someError);
    } else {
      done(null, output);
    }
  }
});

// Call a service
host.callService(
  // The name of the service to call
  'foo',
  // An optional data set to pass to the service
  {},
  // An optional cache key to cache the output of the service
  'some-cache-key',
  // A callback which is provided with the resulting error and output
  function(err, output) {}
);

// Start a process which listens at the configured
// address and port
host.listen();
```


Communicating with the host
---------------------------

### Headers

- `X-Service`: the name of the service that you want to call.
- `X-Cache-Key`: a token used to cache the output of the request,
  all concurrent or subsequent requests will resolve to the same
  output until it expires.

### Sending data

Set the request's content-type to `application/json` and pass the data in 
as the request's body. It will be deserialised and passed to the service.


Configuring the host
--------------------

```javascript
// Default config

var host = new Host({
  // The address that the host will listen at
  address: '127.0.0.1',
  // The port that the host will listen at
  port: '63578',
  // If true, suppresses stdout/stderr from the host and service loggers
  silent: false,
  // If true, the host will write to stdout once it is listening for requests
  outputOnListen: true,
  // The maximum size of an incoming request's body
  requestDataLimit: '10mb',
  // The time between a cache key/value being set and its expiry
  serviceCacheTimeout: 24 * 60 * 60 * 1000, // 24 hours
  // An optional array of services to load during the host's initialization.
  // Services should be objects with `name` and either `file` or `handler`
  // properties. The `file` prop should be a path to a file which exports a
  // handler function.
  services: null
});
```

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