Search code examples
node.jsloopbackjsloopback

loopback - user model not in my folder?


I am using loopback for a project using the prebuilt project for the user model.
However, I am unable to GET the users. I researched and saw that there are ways to change it; however I do not find the user files (user.js and user.json) in common/models, with the other models.
I also cannot see it on my postgres database. Why is that? Should I paste the files (user.json and user.js) from the github repository of loopback and use the script "automigration" to be able to see it?


Solution

  • however I do not find the user files (user.js and user.json) in common/models

    The user model is a built in model, you can find it in node_modules/loopback/common/models.

    I also cannot see it on my postgres database. Why is that? Should I paste the files (user.json and user.js) from the github repository of loopback and use the script "automigration" to be able to see it?

    If you are using the built in models (which you almost certainly are because loopback loads the built in models by default), you can already run the automigrate script from the documentation

    var server = require('./server');
    var ds = server.dataSources.db;
    var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
    ds.automigrate(lbTables, function(er) {
      if (er) throw er;
      console.log('Loopback tables [' + lbTables + '] created in ', ds.adapter.name);
      ds.disconnect();
    });