Benefits of Multi-instance

EggBornJS supports the development of multiple domain sites through the concept of multiple instances

One EggBornJS service can support multiple instances, and the instances shares the same MySQL database architecture, but the data generated dynamically is isolated from each other

Application Scenarios of Multi-instance

For example, we have developed an enterprise business system to provide services to many enterprise users

Instance & Domain

The instance corresponds to the subdomain name of the website one by one, for example:

In the test environment and development environment, EggBornJS has created a default instance; however, in the production environment, need to plan the corresponding relationship between the instance and the subdomain by yourself

Instance Configuration

Because both test environment and development environment use the default instance provided by EggBornJS, only instance parameters need to be configured for the production environment

For example, the official backend of CabloyJS hosts two instances, namely and The configuration of it’s production environment is as follows:


// instances
config.instances = [
  { subdomain: 'admin', password: '', title: 'CabloyJS', config: {} },
  { subdomain: 'zhennann', password: '', title: 'My Blog', config: {} },
Name Description
subdomain If the URL is, the corresponding subdomain is an empty string
password The initial password of the user root for this instance. The default value is 123456
title Website’s title
config instance level configuration, which will override the module level configuration automatically

How to customize the rules of subdomain?

By default, subdomain is obtained based on the secondary domain name. You can modify the rule by modifying the parameter subdomainOffset in the configuration file


  config.subdomainOffset = 1;
  • For Example
domain subdomainOffset subdomain 2 (default) zhennann 1 cabloy.zhennann

How to use Mulit-instance

Reference current instance Id

Because the data between multiple instances is isolated from each other, the condition of current instance id must be taken when performing CRUD operations

// current instance id
const iid =;
// insert
await this.ctx.db.insert('testParty', {
  deleted: 0,
  personCount: 3,
Name Description
ctx.instance current instance object current instance id


The object of model further encapsulates ctx.db, which facilitates support for multi-instance and soft deletion

// insert
  personCount: 3,