Package Exports
- nxus-core
- nxus-core/lib/ConfigurationManager
- nxus-core/lib/test/support/TestApp
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (nxus-core) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 --saveUsage
In your root application, create a new Application instance:
import {Application} from 'nxus-core'
let app = new Application(options)
app.start()
export default appEvents
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 gaurantee execution after the application has completely launched |
Module Loading
By defaul the Application will look for other Nxus modules in the following order:
- @nxus namespaced npm modules in your
package.jsonfile. - Any packages that match the 'namespace-' pattern passed in the
namespaceapplication config option. - folders in the ./modules folder in the root of your project
- 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 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 startwill translate into an application config of
console.log(app.config.myconfig) // {value: {first: true}}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
optsObject the configuration options
Examples
import {application} from 'nxus-core'
application.start()
export default applicationget
Returns an internal ModuleProxy object for the given name.
Parameters
namestring The name of the module to return
Returns ModuleProxy
stop
Stops the currently running application
Returns Promise
start
Starts the Nxus application.
Returns Promise
restart
Restarts the Nxus application.
Returns Promise
Dispatcher
Extends EventEmitter
The core Dispatcher class, which implements promisified
Examples
import { Dispatcher } from 'nxus-core'
class MyClass extends Dispatcher {
...
}once
Bind to an event once
Parameters
eventstring The name of the event to bind tolistener[callable] The handler for the event
Returns 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
eventstring The name of the event to bind tolistenercallable The before handler for the event
after
Bind to after an event. Receives the event handlers results, should return modified results or nothing.
Parameters
eventstring The name of the event to bind tolistenercallable The after handler for the event
onceBefore
Bind once to before an event. Receives the event arguments, should return modified arguments or nothing.
Parameters
eventstring The name of the event to bind tolistenercallable The before handler for the event
Returns 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
eventstring The name of the event to bind tolistenercallable The after handler for the event
Returns Promise Returns a promise that resolves when the event fires
emit
Emits an event, calling all registered handlers.
Parameters
eventstring The name of the event to emit.args...Any Arguments to the event handlers
Returns 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.
Properties
configobject The application configuration for this module.logLogger The logger for the module.