# nxus-core

> A framework for building light-weight, event-driven data processing apps.

Latest version **4.1.4-1** (published 2020-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install nxus-core
pnpm add nxus-core
yarn add nxus-core
bun add nxus-core
```

Provides the command `gonxus`.

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.1.4-1 |
| Published | 2020-01-19 |
| First published | 2016-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ~6 |
| Dependencies | 18 |
| Unpacked size | 83.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | info@nxusapp.com |
| Maintainers | davidkellerman, loppear, mjreich, scottmaxson |

## Links

- npm: https://www.npmjs.com/package/nxus-core
- Repository: https://github.com/nxus/core
- Issues: https://github.com/nxus/core/issues
- npm.io page: https://npm.io/package/nxus-core

## Dependencies (18)

- [rc](https://npm.io/package/rc.md) ^1.1.6
- [chai](https://npm.io/package/chai.md) ^3.5.0
- [async](https://npm.io/package/async.md) ^2.0.1
- [morph](https://npm.io/package/morph.md) ^0.2.0
- [moment](https://npm.io/package/moment.md) ^2.14.1
- [winston](https://npm.io/package/winston.md) ^2.2.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [chokidar](https://npm.io/package/chokidar.md) ^1.6.0
- [multimatch](https://npm.io/package/multimatch.md) ^2.1.0
- [underscore](https://npm.io/package/underscore.md) ^1.8.3
- [deep-extend](https://npm.io/package/deep-extend.md) ^0.4.1
- [stack-trace](https://npm.io/package/stack-trace.md) 0.0.9
- [debug-logger](https://npm.io/package/debug-logger.md) ^0.4.1
- [underscore.deep](https://npm.io/package/underscore.deep.md) ^0.5.1
- [chai-as-promised](https://npm.io/package/chai-as-promised.md) ^5.3.0
- [merge-descriptors](https://npm.io/package/merge-descriptors.md) ^1.0.1
- [babel-plugin-transform-function-bind](https://npm.io/package/babel-plugin-transform-function-bind.md) ^6.8.0
- [babel-plugin-transform-class-properties](https://npm.io/package/babel-plugin-transform-class-properties.md) ^6.11.5

## Recent versions

- 4.1.4-1 (latest) — 2020-01-19
- 4.1.4-0 — 2020-01-19
- 4.1.3 — 2019-03-11
- 4.1.2 — 2018-12-27
- 4.1.1 — 2018-02-27
- 4.1.0 — 2018-02-09
- 4.0.3 — 2017-11-29
- 4.0.2 — 2017-11-26
- 4.0.1 — 2017-07-05
- 4.0.0 — 2017-07-03
- 4.0.0-4 — 2016-12-13
- 4.0.0-3 — 2016-12-12
- 4.0.0-2 — 2016-09-13
- 4.0.0-1 — 2016-09-13
- 4.0.0-0 — 2016-09-09
- … 4 more at https://npm.io/package/nxus-core/versions

## README

# nxus-core

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## Core Module

<style>#toc .h5 { color: #1184CE; font-weight: normal; text-transform: none; letter-spacing: 0; }</style>

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

The Nxus Core package includes the basic Application framework for building a Nxus app.

## Introduction

You'll probably find the following resources useful background and help in building Nxus applcations.

-   [Getting Started](<>) (TODO)
-   [Design Patterns](<>) (TODO)
-   [Nxus Modules](<>) (TODO)
-   [Recipes](<>) (TODO)
-   [Developing a ](<>) (TODO)

## Documentation

The full set of Nxus docs is available at <http://docs.gonxus.org>.

## Installation

    > npm install nxus-core --save

## Usage

In your root application, create a new Application instance:

    import {Application} from 'nxus-core'

    let app = new Application(options)

    app.start()

    export default app

### Events

Nxus is built around the concept of a boot cycle.  The application dispatches events in the following order:

| Boot Stage | Description                                                                                                                                                                          |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `init`     | indicates the application is starting up and initializing modules.  Other modules are not gauranteed to be available at this phase.                                                  |
| `load`     | modules are initialized and loading. This is the place to do any internal setup (outside of the constructor). Other modules are not gauranteed to be available at this phase.        |
| `startup`  | all modules have been loaded and are available. This is the place to do any setup that requires data/input from other modules (like Storage)                                         |
| `launch`   | the application is launching and all services have been started. Routes are accessible. Use onceAfter('launch') to guarantee execution after the application has completely launched |

### Module Loading

By default the Application will look for other Nxus modules in the following order:

1.  @nxus namespaced npm modules in your `package.json` file.
2.  Any packages that match the 'namespace-' pattern passed in the `namespace` application config option.
3.  folders in the ./modules folder in the root of your project
4.  any modules specified in the _modules_ option passed into Application on instantiation.

### Module Access

In order to access module commands, use the Application.get() method.

    let router = Application.get('router')

### Application Configuration

The Application exposes a core `config` object that contains application and module specific configuration values.

Nxus uses the [rc](https://www.npmjs.com/package/rc) library to provide application configuration.

The application configuration can usually be found in a `.nxusrc` file in the root folder.

You can override specific confirguation values using command line environment variables, which supports nesting.

    nxus_myconfig__value__first=true npm start

will translate into an application config of

    console.log(app.config.myconfig) // {value: {first: true}}

You can also pass partial config objects (for run-time override of specific keys) in two ways. An options argument to `application.start()`:

    application.start({module: {key: value}})

Or as a response to the `config` event:

    application.on('config', () => {
      return {module: {key: value}}
    })

`start` options take precendence over `config` event options take precendence over rc or command-line options.

### Mocha Test Configuration

As a convenience, the Nxus Core package provides a
`/lib/test/support/node.js` module that supplies a standard set of
definitions for the Mocha test environment. It includes the Chai
assertion library with ChaiAsPromised extensions, exposes `chai` and
`expect` as global variables, and initializes Chai's `should` assertions.

You can refer to it with Mocha's `--require` option, or include it in a
`mocha.opts` configuration file:

      --require nxus-core/lib/test/support/node


## API




## Application

**Extends Dispatcher**

The Core Application class.

### Configuration Options

Available options are:

| Name      | Description                                                                                                                     |
| --------- | ------------------------------------------------------------------------------------------------------------------------------- |
| appName   | the name of your app. Will be used for console logging.                                                                         |
| appDir    | the location to use to load the default 'package.json' file.                                                                    |
| namespace | any additional namespaces to use to load modules in the node_modules folder. Can be a string or array of strings.               |
| modules   | an array of paths to require into the application                                                                               |
| debug     | Boolean to display debug messages, including startup banner                                                                     |
| script    | Boolean to indicate the application is a CLI script, silences all logging/output messages except for explicit console.log calls |
| silent    | Don't show any console output. Useful for CLI scripts.                                                                          |

**Parameters**

-   `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** the configuration options (optional, default `{}`)

**Examples**

```javascript
import {application} from 'nxus-core'

application.start()

export default application
```

### get

Returns an internal ModuleProxy object for the given name.

**Parameters**

-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the module to return

Returns **ModuleProxy** 

### stop

Stops the currently running application

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** 

### start

Starts the Nxus application.

**Parameters**

-   `opts` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Config to deeply merge with default and rc configs (optional, default `{}`)

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** resolves when the boot sequence is complete

### restart

Restarts the Nxus application.

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** resolves when the restart boot sequence is complete

## Dispatcher

**Extends EventEmitter**

The core Dispatcher class, which implements promisified

**Examples**

```javascript
import { Dispatcher } from 'nxus-core'
class MyClass extends Dispatcher {
  ...
}
```

### once

Bind to an event once

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to bind to
-   `listener` **callable?** The handler for the event

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Returns a promise that resolves when the event fires

### before

Bind to before an event. Receives the event arguments, should return
 modified arguments or nothing.

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to bind to
-   `listener` **callable** The before handler for the event

### after

Bind to after an event. Receives the event handlers results, should return
 modified results or nothing.

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to bind to
-   `listener` **callable** The after handler for the event

### onceBefore

Bind once to before an event. Receives the event arguments, should return
 modified arguments or nothing.

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to bind to
-   `listener` **callable** The before handler for the event

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Returns a promise that resolves when the event fires

### onceAfter

Bind once to after an event. Receives the event handlers results, should return
 modified results or nothing.

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to bind to
-   `listener` **callable** The after handler for the event

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Returns a promise that resolves when the event fires

### emit

Emits an event, calling all registered handlers.

**Parameters**

-   `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of the event to emit.
-   `args` **...any** Arguments to the event handlers

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Returns a promise that resolves when all handlers have completed, with any returned results as an array.

## NxusModule

The NxusModule class is a base class for all Nxus modules.

**Parameters**

-   `app`  

**Properties**

-   `config` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The application configuration for this module.
-   `log` **[Logger](#logger)** The logger for the module.

## Logger

Factory method for instances of the `debug-logger` module.

**Parameters**

-   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** display name used to identify output from the logger (optional, default `'application'`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** `debug-logger` module instance

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