Chinese Documentation : model-config.json

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.  

Icon

You can also use a /client/model-config.json for client-specific (browser) model configuration.

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

model-config.json
{
  "_meta": {
    "sources": [
      "../common/models",
      "./models"
    ]
  },
  "User": {
    "dataSource": "db"
  },
  "AccessToken": {
    "dataSource": "db",
    "public": false
  },
  "ACL": {
    "dataSource": "db",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "db",
    "public": false
  },
  "Role": {
    "dataSource": "db",
    "public": false
  }
}

Model configuration properties

PropertyTypeDescription
_meta.sourcesArrayArray of relative paths to custom model definitions.
model-name.datasourceStringName of data source to which the model is connected
model-name.publicBoolean

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

_meta.sources

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.