App
Module | ejs |
Definition | class App |
Inheritance | App Object |
Specified | ejscript-2.5 |
Stability | Evolving. |
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
Qualifiers | Property | Type | Description |
static | SearchSeparator | String | Separator string to use when constructing PATH style search strings. |
static get | args | Array | Application 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 | cache | Cache | Application in-memory cache reference. |
static | config | Object | Configuration environment specified in the ~/.ejsrc or ejsrc configuration files. |
static get | dir | Path | The application's current directory. |
static | emitter | Emitter | Default event Emitter for the application. |
static get | env | Object | Application environment. Object hash of all environment variables. |
static get set | errorStream | Stream | The application's standard error file stream
Set the standard error stream. Changing the error stream will close and reopen stderr. |
static get | exeDir | Path | The directory containing the application executable. |
static | log | Logger | Application 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 | exePath | Path | The application executable path. |
static get | gid | Number | The group ID of the user account running the application. Only supported on Unix. |
static | mprLog | MprLog | Application MPR log object. This singleton object represents the Application log file specified via the
--log command line switch.
0. |
static | name | String | Application name. Single word, lower-case name for the application. This is initialized to the name of
the script or "ejs" if running interactively. |
static | started | Date | Application start time. |
static | test | | Test object for unit tests when run via utest. |
static | title | String | Application 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 | home | Path | The user's home directory. |
static get set | inputStream | Stream | Set the standard input stream. Changing the input stream will close and reopen stdin. |
static get set | outputStream | Stream | The standard output stream. Changing the output stream will close and reopen stdout. |
static get | pid | Number | The process ID of the application. |
static get set | search | Array | The current module search path. Set to an array of Paths. |
static get | uid | Number | The user ID of the user account running the application. Only supported on Unix. |
static | version | String | Application version string. Set to a version string [format Major.Minor.Patch-Build]. For example: 1.1.2-3.
Initialized to the ejs version. |
Inherited Properties
App Class Methods
Qualifiers | Method |
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. |
Inherited Methods
App Instance Methods
Qualifiers | Method |
(No own instance methods defined)
Inherited Methods
Method Detail
- Description
- Change the application's working directory.
- Parameters
value: Object | The path to the new working directory. |
- 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.
- 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] |
- 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.
- Description
- Get a password from the user's /dev/tty.
- Returns
- A clear-text password string.
- 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] |
- 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. |
- 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.
- 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] |
- Description
- Redirect the Application's logger based on the App.config.log setting
Ignored if app is invoked with --log on the command line.