Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

billy

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

billy

A minimal application harness that stays out of your way and out of your code.

  • 1.7.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-92.59%
Maintainers
1
Weekly downloads
 
Created
Source

billy

Build Status NPM version

A minimal application harness that stays out of your way and out of your code.

browser support

Installation

$ npm install billy

Usage

import Application from 'billy';

let app = new Application();

app.service(function main() {
  console.log('Hello, World!');
});

app.start();

Features

Overview

The primary goal and driving philosophy of Billy is to provide a cohesive and useful set of patterns for building an application that doesn't creep its way into your business logic and domain code.

It is flexible and generic enough to work great for building server apps, browser apps, javascript games, or even CLI utilities.

Much like express, Billy strives not to be a framework that permeates all parts of your codebase, but rather the scaffolding that allows you to roll your own application architecture stack.

Services

Billy views your application as the composition of several dependency-injected Services. When the application is started via app.start(), all registered services will be instantiated in turn and be given a chance to startup.

A service should be used to create various run-time objects and register them as dependencies with the IoC container via the app dependency for other parts of the application to use.

Services are effectively the place where all the various pieces of your application are booted, configured, and wired together.

Registering a service

Your application entry point will register a series of services that will power your app. Services can either be a simple closure or a class constructor, and can optionally use promises to signal an asynchronous startup.

Using closures as a Service

The simplest example of a service is a function:

app.service(() => {
  console.log('service created');
});

If our service took some time to startup, we could return a Promise to ensure during the service start phase, the application would wait.

app.service(async () => {
  console.log('service created');
  await someAsyncTask();
  console.log('service started');
});

Note that all services are first created all at once (by calling the provided function), synchronously. Then, all of the services are started (by waiting on any promises returned in the service function).

Using Class Constructors as a Service

A simple class constructor can be passed to the app.service() method as well.

// MyService.js

export default class MyService
{
  constructor()
  {
    console.log('service created');
  }
}

In our startup file:

// main.js
import Application from 'billy';
import MyService from './MyService.js';

let app = new Application();

app.service(MyService);
app.start();

If this service requires some additional setup after all services have been created, or requires an asynchronous startup, we can implement a start method:

export default class MyService
{
  async start()
  {
    await someAsyncTask();
    console.log('service started');
  }
}

Any promise return is waited on until it resolves before attempting to start any subsequent services.

This is useful for things like downloading external data, verifying credentials, bootstrapping external connections, etc. The application startup process will block until the service resolves, guaranteeing a deterministic boot up.

Testing

$ npm test

Documentation

This will generate the HTML documentation under ./doc:

$ npm run doc

License

MIT

FAQs

Package last updated on 30 Nov 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc