Structure of a Node.js Service Repository
A Node.js service repository has to be a ZIP file containing at least two elements:
- A file package.json containing some service information the Bridge needs for managing the service.
If your Node.js service needs additional modules (libraries), you need to install all modules locally and include the sub-folder node_modules. You cannot install modules globally to the Bridge Node.js.
You can use 'npm install' to install those additional modules (see Deploying a Node.js Service Repository via the E2E Bridge).
Structure of package.json
The following json elements are required in the file package.json:
|name||Contains the name of the Node.js service as displayed on the Bridge. This is the name taken into account when applying the option Overwrite Service.||mandatory|
|version||Contains the version of the Node.js service.||optional|
|description||Contains a description of the Node.js service.||optional|
Contains the call to start the Node.js service:
Additional json elements can be added to package.json as needed (e.g. for adding packages/libraries), but will be ignored by the Bridge.
The Bridge provides some environment variables that are strongly recommended to be used by developers in their code:
Node.js service port
Path to the configuration directory of the service (within the working directory of the service).
If you use the e2e-conf Node.js module, you can initialize e2e-conf with E2E_CONF_ROOT. This is especially useful if your e2e-conf is not a top level dependency but a sub-module dependency.
If the Node.js service writes log files in this directory, you can view them in the Bridge.
Do not use the following prefixes: start, stdout, stderr and transaction. They are reserved prefixes by the Bridge.
These special environment variables are displayed on the details tab of any Node.js service. Add and configure them on tab Environment Variables of the Node.js service (see Setting Environment Variables for Node.js Services).
Writing to Bridge Log Files
Trigger Bridge Monitoring From the Error Log
Bridge 7.3.0 The Bridge comes with a built-in monitoring functionality, which can catch failure events for any service running on the Bridge (see Bridge Monitoring). If such an error event occurs, the Bridge calls the registered monitoring service, that executes whatever has to be done in this case, for instance sending an e-mail to the system administrator. The monitoring service is just another SOAP service that is running on the Bridge and is registered as monitoring service.
The monitoring service has a standardized interface (see Monitoring ) to which you need to provide the necessary data with your Node.js log. Generally, all lines from stderr are written to the Bridge error log as they are. As the Bridge will read this information from your Node.js logs and provide it to the monitoring service, your log file should have the following structure:
|Log Field Name||Description||Log Examples||Monitoring Interface||Monitoring Examples|
Timestamp in local system time, time part only. The Bridge will add the date part and convert the date/time to UTC.
The timestamp is the marker for the beginning of a log entry.
The Bridge will only forward log messages with log level
|Service/ Domain||Service identifier of the Node.js service. Provide here two values separated by a '||service|
|Code||The error code of the error.||code|
|Unused 1||Two dummy fields which are needed for internal compatibility reasons. If you log some information here, this will be ignored by the Bridge.|
The actual error message, separated by '
The error message may contain multiple lines. The timestamp is the marker for the beginning of a new log entry.
|Automatically provided by the Bridge.||host|
|Automatically provided by the Bridge.||processID|
|Automatically provided by the Bridge. The Bridge will provide this value as ||category|
|Automatically provided by the Bridge. The Bridge will provide the path to the corresponding Node.js service log file.||detailLocation|
Implementing a Service Shutdown Activity
Bridge 7.2.0 Upon stopping a Node.js service, the Bridge will send an operating system signal (
SIGINT) to the service to stop it. If you want to do some clean-up actions before stopping, you have to implement a signal handler for
SIGINT in your Node.js service.
For more information, refer to the Node.js documentation on signal events.