New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

service-host

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

service-host

JS service host

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

service-host

Build Status

Installation

npm install service-host

CLI usage

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

Config files should export an object.

Programmatic usage

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

// 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
});

FAQs

Package last updated on 29 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts