new App(basePath, argv)
Create app
Parameters:
| Name | Type | Description |
|---|---|---|
basePath |
string | Path to the root of the project |
argv |
Array.<string> | Command line arguments |
Members
-
<static> fatalExitCode :number
-
Fatal error exit code
Type:
- number
-
<static> gracefulTimeout :number
-
Graceful shutdown timeout
Type:
- number
-
<static> signals :Array.<string>
-
Catched signals
Type:
- Array.<string>
Methods
-
registerInstance(instance, name)
-
Register an instance of a service
Parameters:
Name Type Description instance* Instance namestring Name Returns:
Returns name of the service- Type
- string
-
registerClass(classFunc [, filename])
-
Register class function as a service
Parameters:
Name Type Argument Description classFuncfunction Class function filenamestring <optional>
Path to the file Returns:
Returns name of the service- Type
- string
-
has(name)
-
Check if service is registered
Parameters:
Name Type Description namestring Service name Returns:
- Type
- boolean
-
get(name, extra)
-
Get instance of a service
Parameters:
Name Type Argument Description namestring | RegExp Service name or RegExp of names extra* <repeatable>
Optional extra arguments to the constructor Returns:
Returns instance or Map of instances in case of RegExp- Type
- object | Map
-
search(re)
-
Search registered services
Parameters:
Name Type Description reRegExp Service name RegExp Returns:
Returns array of matching service names- Type
- Array.<string>
-
<async> debug(messages)
-
Debug output
Parameters:
Name Type Argument Description messages* <repeatable>
Messages Returns:
- Type
- Promise
-
<async> info(messages)
-
Info output
Parameters:
Name Type Argument Description messages* <repeatable>
Messages Returns:
- Type
- Promise
-
<async> error(messages)
-
Error output
Parameters:
Name Type Argument Description messages* <repeatable>
Messages Returns:
- Type
- Promise
-
<async> run( [options], {boolean, args)
-
Run the app. This method will simply call .init() and then .start().
Parameters:
Name Type Argument Description optionsobject <optional>
Arpen options Properties
Name Type Argument Default Description cacheServicesboolean <optional>
true When true services cache will not be used {boolean[options.interceptConsole=true] Redirect console.log(), etc. to default logger args* <repeatable>
Descendant class specific arguments Returns:
- Type
- Promise
-
<async> exit(code [, message])
-
Terminate the app. Will call .stop() with start args
Parameters:
Name Type Argument Default Description codenumber 0 Exit code, default is 0 messagestring <optional>
Exit log message Returns:
- Type
- Promise
-
<async> init(args)
-
Initialize the app
Parameters:
Name Type Argument Description args* <repeatable>
Descendant class specific arguments Returns:
- Type
- Promise
-
<async> start(args)
-
Start the app. Should be overridden.
Descendant must call this (parent) method and start the appParameters:
Name Type Argument Description args* <repeatable>
Descendant class specific arguments Returns:
- Type
- Promise
-
<async> stop(args)
-
Stop the app. Should be overridden.
Descendant must call this (parent) method and stop the appParameters:
Name Type Argument Description args* <repeatable>
Descendant-specific arguments Returns:
- Type
- Promise
-
<async> onSignal(signal)
-
Handle process signal
Parameters:
Name Type Description signalstring Signal as SIGNAME Returns:
- Type
- Promise
-
<async> _initConfig()
-
Load the configuration
Returns:
- Type
- Promise
-
<async> _initSources()
-
Load the source files
Returns:
- Type
- Promise
-
<async> _initModules()
-
Create modules
Returns:
- Type
- Promise
-
_initService(name [, filename])
-
Initialize as empty and return the item of service container, adding new one if it does not exist yet
Parameters:
Name Type Argument Description namestring Name of the service filenamestring <optional>
Path to the class Returns:
Returns service object- Type
- object
-
_resolveService(name, extra, request)
-
Resolve dependencies and return an instance of a service
Parameters:
Name Type Description namestring Service name extraArray Extra constructor arguments requestMap Resolved dependencies Returns:
Returns instance of the service- Type
- object
-
_instantiateClass(service, extra, request)
-
Instantiate given service class
Parameters:
Name Type Description serviceobject Service object extraArray Extra constructor arguments requestMap Resolved dependencies Returns:
Returns instance of the class- Type
- object
-
<async> _output(stream, messages)
-
Print output
Parameters:
Name Type Description stream* Stream for output messagesArray Messages Returns:
- Type
- Promise
-
<async> _autoload(basePath, dirs)
-
Load given directories
Parameters:
Name Type Description basePathstring Base path dirsArray.<string> Directories Returns:
- Type
- Promise
-
<async, static> _require(filename [, defaultObject])
-
Load js file
Parameters:
Name Type Argument Description filenamestring Path of the file defaultObject* <optional>
If specified this will be returned if file could not be loaded Returns:
Resolves to the exported object- Type
- Promise