You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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.
  • All JavaScript source code and resources.

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": "HelloWorld",
  "version": "0.0.1",
  "description": "Hello world HTTP server",
  "scripts": {
  "start": "node server.js"
  },
}
ElementDescriptionMandatory
nameContains 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
versionContains the version of the Node.js service.optional
descriptionContains a description of the Node.js service.optional
scripts/start

Contains the call to start the Node.js service: node <name of the start JavaScript file>.js

mandatory

Additional json elements can be added to package.json as needed (e.g. for adding packages/libraries), but will be ignored by the Bridge.

Environment Variables

The Bridge provides some environment variables that are strongly recommended to be used by developers in their code:

Variable

Description

Default

PORT

Node.js service port

-

CONFIG_DIR

Path to the configuration directory of the service (within the working directory of the service).

  • All configuration files (e.g. service settings) that are stored in this location will survive a Node.js service update. Files that have been saved to the working directory only, will be deleted on update.

  • This directory will be created by the Bridge on service startup, if not existent.

repository/config/local

E2E_CONF_ROOT

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.

repository

E2E_LOGS

If the Node.js service writes log files in this directory, you can view them in the Bridge.

  • If the log file keeps growing, you should rotate the log file per day and use this naming pattern:

    <prefix>_YYYY-MM-DD.log.

  • If the log file has a fixed size, you can use the naming pattern <prefix>.log.

Do not use the following prefixes: start, stdout, stderr and transaction. They are reserved prefixes by the Bridge.

logs


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

If you are writing messages to log files that will be displayed on the Bridge (npm-install, start, stdout, stderr, custom logfiles), you must use UTF-8 encoding. If you do not, special characters may be displayed wrongly in the log view.

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.

  • No labels