App

Moduleejs
Definition class App
InheritanceApp inherit Object
Specifiedejscript-2.5
StabilityEvolving.

Application configuration state.

The App class is a singleton class object and that accesses and controls the applications execution environment including the current working directory, application command line arguments, environment strings, path to the application's executable and input and output streams.


Properties

QualifiersPropertyTypeDescription
static SearchSeparatorStringSeparator string to use when constructing PATH style search strings.
static get argsArrayApplication command line arguments. Set to an array containing each of the arguments. If the ejs command is invoked as "ejs script arg1 arg2", then args[0] will be "script", args[1] will be "arg1" etc.
static cacheCacheApplication in-memory cache reference.
static configObjectConfiguration environment specified in the ~/.ejsrc or ejsrc configuration files.
static get dirPathThe application's current directory.
static emitterEmitterDefault event Emitter for the application.
static get envObjectApplication environment. Object hash of all environment variables.
static get set errorStreamStreamThe application's standard error file stream Set the standard error stream. Changing the error stream will close and reopen stderr.
static get exeDirPathThe directory containing the application executable.
static logLoggerApplication logger. This singleton object respresents the Application default logger. If the ejsrc startup configuration file defines a log.location field, the log logger will send messages to the defined location. Otherwise, messages will be sent to the MprLog stream. (.
static get exePathPathThe application executable path.
static get gidNumberThe group ID of the user account running the application. Only supported on Unix.
static mprLogMprLogApplication MPR log object. This singleton object represents the Application log file specified via the --log command line switch. 0.
static nameStringApplication name. Single word, lower-case name for the application. This is initialized to the name of the script or "ejs" if running interactively.
static startedDateApplication start time.
static test Test object for unit tests when run via utest.
static titleStringApplication title name. Multi-word, Camel Case name for the application suitable for display. This is initialized to the name of the script or "Embedthis Ejscript" if running interactively.
static get homePathThe user's home directory.
static get set inputStreamStreamSet the standard input stream. Changing the input stream will close and reopen stdin.
static get set outputStreamStreamThe standard output stream. Changing the output stream will close and reopen stdout.
static get pidNumberThe process ID of the application.
static get set searchArrayThe current module search path. Set to an array of Paths.
static get uidNumberThe user ID of the user account running the application. Only supported on Unix.
static versionStringApplication version string. Set to a version string [format Major.Minor.Patch-Build]. For example: 1.1.2-3. Initialized to the ejs version.

App Class Methods

QualifiersMethod
static chdir(value: Object): Void
 Change the application's working directory.
static createSearch(searchPath: String = null): Array
 Create a search path array for locating ejs modules.
static exit(status: Number = 0, how: String = normal, timeout: Number = 0): Boolean
 Stop the program and exit.
static getenv(name: String): String
 Get an environment variable.
static getpass(prompt: String): String
 Get a password from the user's /dev/tty.
static loadrc(path: Path, overwrite: Boolean = true)
 Load an "ejsrc" configuration file This loads an Ejscript configuration file and blends the contents with App.config.
static putenv(name: String, value: String): Void
 Update an environment variable.
static run(timeout: Number = -1, oneEvent: Boolean = false): Boolean
 Run the application event loop.
static sleep(delay: Number = -1): Void
 Sleep the application for the given number of milliseconds.
static updateLog(): Void
 Redirect the Application's logger based on the App.config.log setting Ignored if app is invoked with --log on the command line.

App Instance Methods

(No own instance methods defined)

QualifiersMethod

Method Detail

static chdir(value: Object): Void
Description
Change the application's working directory.
Parameters
value: Object The path to the new working directory.

static createSearch(searchPath: String = null): Array
Description
Create a search path array for locating ejs modules. This converts a delimited PATH to an array of paths suitable for use by the search property. NOTE: this does not modify the application's search path.
Parameters
searchPath: String String containing a colon separated (or semi-colon on Windows) set of paths. If search path is null, the default system search paths are returned. [default: null]
Returns
An array of search paths.

static exit(status: Number = 0, how: String = normal, timeout: Number = 0): Boolean
Description
Stop the program and exit.
Parameters
status: Number The optional exit code to provide the environment. If running inside the ejs command program, the status is used as process exit status. [default: 0]
how: String How the exit should proceed. Options are: "abort", "safe" or "normal". An option of "abort" will immediately abort the application without flushing buffered data. An option of "normal" which is the default, will wait for the application to become idle before exiting. A application is idle when it has no running commands, sockets, Http requests or worker threads. An option of "safe" will try to exit, but if after the timeout expires the application is still not idle, the exit will be cancelled and this routine will return false. [default: normal]
timeout: Number Time period in milliseconds to wait for the application to become idle before exiting. Defaults to zero. [default: 0]

static getenv(name: String): String
Description
Get an environment variable.
Parameters
name: String The name of the environment variable to retrieve.
Returns
The value of the environment variable or null if not found.

static getpass(prompt: String): String
Description
Get a password from the user's /dev/tty.
Returns
A clear-text password string.

static loadrc(path: Path, overwrite: Boolean = true)
Description
Load an "ejsrc" configuration file This loads an Ejscript configuration file and blends the contents with App.config.
Parameters
path: Path Path name of the file to load.
overwrite: Boolean If true, then new configuration values overwrite existing values in App.config. [default: true]

static putenv(name: String, value: String): Void
Description
Update an environment variable.
Parameters
name: String The name of the environment variable to retrieve.
value: String The new value to define for the variable.

static run(timeout: Number = -1, oneEvent: Boolean = false): Boolean
Description
Run the application event loop. A script may call run() to service events. Calling run() will cause the ejs shell to wait and service events until instructed to exit via App.exit. If the application is hosted in a web server, this routine will return true immediately without blocking.
Parameters
timeout: Number Timeout to block waiting for an event in milliseconds before returning. If an event occurs, the call returns immediately. Set to -1 for no timeout. [default: -1]
oneEvent: Boolean If true, return immediately after servicing at least one ejs event. [default: false]
Returns
True if an event happened. Otherwise return false if the timeout expired before any event.

static sleep(delay: Number = -1): Void
Description
Sleep the application for the given number of milliseconds. Events will be serviced while asleep. An alternative to sleep is App.run which can be configured to sleep and return early if an event is received.
Parameters
delay: Number Time in milliseconds to sleep. Set to -1 to sleep forever. [default: -1]

static updateLog(): Void
Description
Redirect the Application's logger based on the App.config.log setting Ignored if app is invoked with --log on the command line.