# leverage-js

> A highly modular server library!

Latest version **1.3.1** (published 2017-09-26) · ISC license · 0 weekly downloads

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

## Install

```sh
npm install leverage-js
pnpm add leverage-js
yarn add leverage-js
bun add leverage-js
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2017-09-26 |
| First published | 2017-03-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jake Hamilton |
| Maintainers | jakehamilton |
| Keywords | leverage, server, express |

## Links

- npm: https://www.npmjs.com/package/leverage-js
- Repository: https://github.com/jakehamilton/leverage
- Homepage: https://github.com/jakehamilton/leverage#readme
- Issues: https://github.com/jakehamilton/leverage/issues
- npm.io page: https://npm.io/package/leverage-js

## Dependencies (2)

- [klaw](https://npm.io/package/klaw.md) *
- [express](https://npm.io/package/express.md) ^4.15.2

## Recent versions

- 1.3.1 (latest) — 2017-09-26
- 1.3.0 — 2017-09-25
- 1.2.3 — 2017-08-04
- 1.2.2 — 2017-08-04
- 1.2.1 — 2017-08-04
- 1.2.0 — 2017-08-04
- 1.1.7 — 2017-07-28
- 1.1.6 — 2017-07-26
- 1.1.5 — 2017-07-26
- 1.1.4 — 2017-07-26
- 1.1.3 — 2017-07-26
- 1.1.2 — 2017-07-26
- 1.1.1 — 2017-07-05
- 1.1.0 — 2017-07-05
- 1.0.2 — 2017-07-05
- … 11 more at https://npm.io/package/leverage-js/versions

## README

<img src="/markdown-assets/leverage.png" width="80" height="80">

What is it?
-----------

👩‍💻 A super fast, super customizable library to orchestrate your next application.

What can you use it for?
------------------------

+ A HTTP server
+ A chat bot
+ A realtime websocket server
+ An IRC server
+ A MIDI interface
+ 👩💭 Anything else you can imagine!

Install it
----------

```bash
npm i -S leverage-js
```

Hello World
-----------

For a "Hello World", we'll create a simple http server that responds to requests with a "Hello World".

First, install the HTTP plugin:

```bash
npm i -S leverage-plugin-http
```

Now, we will write an HTTP component and load our component and the HTTP plugin:

```js
import { manager, Component } from 'leverage-js'
import http from 'leverage-plugin-http'

const component = Component.of({
    config: {
        type: 'http',
        http: {
            path: '*',
            method: 'get'
        }
    },
    http (request, response) {
        response.send('Hello World')
    }
})

manager.add(component, http)

http.listen(3000)
```

Run the above and head over to [localhost:3000](http://localhost:3000) to see it in action!

Documentation and Tutorials
---------------------------

Please see [the project's wiki](https://github.com/jakehamilton/leverage/wiki) 🚀.

API
---

### Leverage.createComponent()

This is an alias for `Component.of` and allows you to create a
component instance by passing this method a component definition.

Example:

```js
import { createComponent } from 'leverage-js'

const component = createComponent({
    config: {
        type: 'http'
    }
})
```

### Leverage.createMiddleware()

This is an alias for `Middleware.of` and allows you to create a
middleware instance by passing this method a middleware definition.

Example:

```js
import { createMiddleware } from 'leverage-js'

const middleware = createMiddleware({
    config: {
        type: 'http'
    }
})
```

### Leverage.createService()

This is an alias for `Service.of` and allows you to create a
service instance by passing this method a service definition.

Example:

```js
import { createService } from 'leverage-js'

const service = createService({
    config: {
        type: 'http'
    }
})
```

### Leverage.createPlugin()

This is an alias for `Plugin.of` and allows you to create a
plugin instance by passing this method a plugin definition.

Example:

```js
import { createPlugin } from 'leverage-js'

const plugin = createPlugin({
    config: {
        type: 'http'
    }
})
```

### Leverage.Component

The `Component` class lets you create your own components. You can extend it
using the `class` syntax or use `Component.of` to extend using a normal object.

Example (with class syntax):

```js
import { Component } from 'leverage-js'

class MyComponent extends Component {
    constructor () {
        super()

        this.config = {
            type: 'http'
        }
    }
}
```

##### Component.config

The `config` object is a component's special configuration object and defines
how the component should be used.

##### Component.of()

You can create a component instance by calling this method with component
definition object.

Example:

```js
import { Component } from 'leverage-js'

Component.of({
    config: {
        type: 'http'
    }
})
```

### Leverage.Middleware

The `Middleware` class lets you create your own middleware. You can extend it
using the `class` syntax or use `Middleware.of` to extend using a normal object.

Example (with class syntax):

```js
import { Middleware } from 'leverage-js'

class MyComponent extends Middleware {
    constructor () {
        super()

        this.config = {
            type: 'http'
        }
    }
}
```

##### Middleware.config

The `config` object is a middleware's special configuration object and defines
how the middleware should be used.

##### Middleware.of()

You can create a middleware instance by calling this method with middleware
definition object.

Example:

```js
import { Middleware } from 'leverage-js'

Middleware.of({
    config: {
        type: 'http'
    }
})
```

### Leverage.Service

The `Service` class lets you create your own service. You can extend it
using the `class` syntax or use `Service.of` to extend using a normal object.

Example (with class syntax):

```js
import { Service } from 'leverage-js'

class MyComponent extends Service {
    constructor () {
        super()

        this.config = {
            name: 'myService'
        }
    }
}
```

##### Service.config

The `config` object is a service's special configuration object and defines
how the service should be used.

##### Service.of()

You can create a service instance by calling this method with service
definition object.

Example:

```js
import { Service } from 'leverage-js'

Service.of({
    config: {
        name: 'myService'
    }
})
```

### Leverage.Plugin

The `Plugin` class lets you create your own plugin. You can extend it
using the `class` syntax or use `Plugin.of` to extend using a normal object.

Example (with class syntax):

```js
import { Plugin } from 'leverage-js'

class MyComponent extends Plugin {
    constructor () {
        super()

        this.config = {
            type: 'http'
        }
    }
}
```

##### Plugin.config

The `config` object is a plugin's special configuration object and defines
how the plugin should be used.

##### Plugin.of()

You can create a plugin instance by calling this method with plugin
definition object.

Example:

```js
import { Plugin } from 'leverage-js'

Plugin.of({
    config: {
        type: 'http'
    }
})
```

### Leverage.manager

Leverage's manager handles loading components, plugins, middleware, and services.

##### manager.add()

`manager.add` will load leverage modules from arguments, arrays, or directory path.

Example:

```js
import { manager, Component, Plugin, Service, Middleware } from 'leverage-js'

manager.add(
    Component.of({ config: { type: 'some-type' } }),
    Plugin.of({ config: { type: 'some-type', identifier: 'some-id' } }),
    Service.of({ config: { name: 'some-name' } }),
    Middleware.of({ config: { type: 'some-type' } })
)
```

##### manager.component()

`manager.component` will load a component instance.

Example:

```js
import { manager, Component } from 'leverage-js'

const component = Component.of({
    config: {
        type: 'http'
    }
})

manager.component(component)
```

##### manager.plugin()

`manager.plugin` will load a plugin instance.

Example:

```js
import { manager, Plugin } from 'leverage-js'

const plugin = Plugin.of({
    config: {
        type: 'http',
        identifier: 'path'
    },
    http (component) {

    }
})

manager.plugin(plugin)
```

##### manager.service()

`manager.service` will load a service instance.

Example:

```js
import { manager, Service } from 'leverage-js'

const service = Service.of({
    config: {
        name: 'myService'
    }
})

manager.service(service)
```

##### manager.middleware()

`manager.middleware` will load a middleware instance

Example:

```js
import { manager, Middleware } from 'leverage-js'

const middleware = Middleware.of({
    config: {
        type: 'http'
    }
})

manager.middleware(middleware)
```

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