Page Contents

Overview

The file /server/model-config.json configures LoopBack models, for example it binds models to data sources and specifies whether a model is exposed over REST. The models referenced in this file must be either a built-in models or custom models defined by a JSON file in the common/models/ folder.

For example, here is the default model-config.json that lists all the built-in models:

model-config.json

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "db"
  },
  "AccessToken": {
    "dataSource": "db",
    "public": false
  },
  "ACL": {
    "dataSource": "db",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "db",
    "public": false
  },
  "Role": {
    "dataSource": "db",
    "public": false
  }
}

Top-level properties

Property Type Description
_meta.sources Array

Array of relative paths to custom model definitions.

By default, LoopBack applications load models from /common/models subdirectory. To specify a different location (or even multiple locations) use the  _meta.sources property, whose value is an array of directory paths.

_meta.mixins Array Array of relative paths to custom mixin definitions. See Defining mixins for more information.
modelName String Name of a model, either a built-in model or a custom model defined in the common/models/ folder.

Model properties

Each JSON key is the name of a model and an object with the following properties.

Property Type Description
datasource String

Name of the data source to which the model is connected. Must correspond to a data source defined in datasources.json.

public Boolean

Whether the model API is exposed.

If true, then the model is exposed over REST. Does not affect accessibility of Node API.