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 name
string Name Returns:
Returns name of the service- Type
- string
-
registerClass(classFunc [, filename])
-
Register class function as a service
Parameters:
Name Type Argument Description classFunc
function Class function filename
string <optional>
Path to the file Returns:
Returns name of the service- Type
- string
-
has(name)
-
Check if service is registered
Parameters:
Name Type Description name
string Service name Returns:
- Type
- boolean
-
get(name, extra)
-
Get instance of a service
Parameters:
Name Type Argument Description name
string | 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 re
RegExp 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 options
object <optional>
Arpen options Properties
Name Type Argument Default Description cacheServices
boolean <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 code
number 0 Exit code, default is 0 message
string <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 signal
string 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 name
string Name of the service filename
string <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 name
string Service name extra
Array Extra constructor arguments request
Map Resolved dependencies Returns:
Returns instance of the service- Type
- object
-
_instantiateClass(service, extra, request)
-
Instantiate given service class
Parameters:
Name Type Description service
object Service object extra
Array Extra constructor arguments request
Map Resolved dependencies Returns:
Returns instance of the class- Type
- object
-
<async> _output(stream, messages)
-
Print output
Parameters:
Name Type Description stream
* Stream for output messages
Array Messages Returns:
- Type
- Promise
-
<async> _autoload(basePath, dirs)
-
Load given directories
Parameters:
Name Type Description basePath
string Base path dirs
Array.<string> Directories Returns:
- Type
- Promise
-
<async, static> _require(filename [, defaultObject])
-
Load js file
Parameters:
Name Type Argument Description filename
string 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