Search code examples
node.jsloopbackjsstrongloop

JavaScript not executing file in models folder


I have generated an app using strongloop and added the following code in user.js

// user.js
console.log("came here");
module.exports = function(app) {
  console.log(app);
};

Why I cannot see any console? Why is this file not being included while running the server?


Solution

  • Since you are using user instead of User I am assuming you extended the default User class (case sensitive). If not, you have to https://docs.strongloop.com/display/public/LB/Customizing+models

    Some examples use "user" which is an extended "User" class but I always use a different name to prevent confusion (such as mentionned by @amuramoto, customer)

    1. Check that you have a models/your_user_class.json
    2. Check that your user class is in /server/model-config.json
    3. Add your js file (beware the case) in models/your_user_class.js

    Note that in module.exports = function(app), app will be the model. Rename this way module.exports = function(Customer) (for example) and access the app object with Customer.app