title: How can I use custom loopback models in server.js
body: <p>I'd like to use custom loopback model in server.js like below.</p>
  
  <p><strong>server/server.js</strong></p>
  
  <pre><code>app.start = function() {
    // start the web server
    return app.listen(function() {
      app.emit('started');
      console.log('Web server listening at: %s', app.get('url'));
    });
  };
  
  if (require.main === module) {
    var server = app.start();
    app.models.Foo.something(); // &lt;- call method here
  }
  </code></pre>
  
  <p><strong>common/models/foo.js</strong></p>
  
  <pre><code>module.exports = function(Foo) {
    Foo.prototype.something = function() {
      console.log('Hi');
      return true;
    };
  
    Foo.setup = function() {
      Foo.base.setup.apply(this, arguments);
    };
    Foo.setup();
  };
  </code></pre>
  
  <p>ref: <a href="https://gist.github.com/bajtos/213d5dae87e19f47db5d" rel="nofollow">https://gist.github.com/bajtos/213d5dae87e19f47db5d</a></p>
  
  <p><br></p>
  
  <p>But actually I got a error like this.</p>
  
  <pre><code>/Projects/repo/server/server.js:45   
    app.models.Foo.something();
                       ^
  TypeError: Object function ModelConstructor(data, options) {
        if (!(this instanceof ModelConstructor)) {
          return new ModelConstructor(data, options);
        }
        if (ModelClass.settings.unresolved) {
          throw new Error('Model ' + ModelClass.modelName + ' is not defined.');
        }
        ModelBaseClass.apply(this, arguments);
      } has no method 'something'
      at Object.&lt;anonymous&gt; (/Projects/repo/server/server.js:45:22)
      at Module._compile (module.js:456:26)
      at Object.Module._extensions..js (module.js:474:10)
  </code></pre>
  
  <p><br></p>
  
  <p>The method seems not to be defined. How to use custom methods in launching server and how can I correct it?</p>