Configure data sources in datasources.json.
Page Contents

Overview

Configure data sources in /server/datasources.json. You can set up as many data sources as you want in this file. The easiest way to set up a new data source is to use the data source generator, which will prompt your for all the appropriate settings, add them to /server/datasources.json, and then install the connector from npm.

For example:

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "mySQLdb": {
    "name": "mySQLdb",
    "connector": "mysql",
    "host": "demo.strongloop.com",
    "port": 3306,
    "database": "demo",
    "username": "demo",
    "password": "L00pBack"
  }
}

To store data in a file for memory connector, add "file": "file_name". For more information see Memory connector - data persistence.

For example:

{
  "db": {
    "name": "db",
    "connector": "memory",
    "file": "db.json",
  },
}

To access data sources in application code, use app.datasources.datasourceName.

Standard properties

All data sources support a few standard properties. Beyond that, specific properties and defaults depend on the connector being used.

Property Description
connector LoopBack connector to use:
  • memory
  • loopback-connector-oracle or just "oracle"
  • loopback-connector-mongodb or just "mongodb"
  • loopback-connector-mysql or just "mysql"
  • loopback-connector-postgresql or just "postgresql"
  • loopback-connector-soap or just "soap"
  • loopback-connector-mssql or just "mssql"
  • loopback-connector-rest or just "rest"
  • loopback-component-storage
  • Another LoopBack data source connector
name Name of the data source being defined.

Database connector properties

Although each data source connector has a different set of properties, database connectors typically have properties that include properties for the database server and credentials to log in to it.

For information on the properties that each connector supports, see the specific connector documentation in Database connectors.

The following table list common properties that most database connectors provide. See documentation for the specific connector for full details.

Property Type Description
database String Database name
host String Database host name
password String Password to connect to database
port Number Database TCP port
url String Connection URL that overrides other connection settings.
username String Username to connect to database

To connect a model to a data source, follow these steps to create a datasource.