0
votes

I am new in loopback,

I trying to work user models like register,login. I followed this url - https://github.com/strongloop/loopback-example-user-management

Its working good but its working without postgres database.

I added the code datasoruces.json.

{
    "db": {
        "name": "db",
        "connector": "memory"
    },
    "mydata": {
        "postgres": {
            "host": "localhost",
            "port": "5432",
            "database": "myapps_login",
            "username": "postgres",
            "password": "password",
            "name": "postgres",
            "debug": true,
            "connector": "postgresql"
        }
    }

How can I access user model using database?

1

1 Answers

0
votes

There are two issues. First is that you did not define your datasource correctly. You should not have a nested postgres object:

"mydata": {
    "name": "mydata",
    "host": "localhost",
    "port": "5432",
    "database": "myapps_login",
    "username": "postgres",
    "password": "password",
    "debug": true,
    "connector": "postgresql"
}

Next, you need to attach the User model to your new datasource. Edit the server/model-config.json file:

{
  // ...
  "User": {
    "dataSource": "mydata",
    "public": true
  },
  // ...
}

Lastly, make sure you have installed the postgres connector dependency (from your command line, in your project directory):

npm install --save loopback-connector-postgresql